{-# LANGUAGE CPP #-}
module Data.IntMap.Optics
( toMapOf
, lt
, gt
, le
, ge
) where
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Optics.IxAffineTraversal
import Optics.IxFold
import Optics.Optic
toMapOf
:: (Is k A_Fold, is `HasSingleIndex` Int)
=> Optic' k is s a -> s -> IntMap a
toMapOf :: Optic' k is s a -> s -> IntMap a
toMapOf Optic' k is s a
o = Optic' k is s a -> (Key -> a -> IntMap a) -> s -> IntMap a
forall (k :: OpticKind) (m :: OpticKind) (is :: IxList)
(i :: OpticKind) (s :: OpticKind) (a :: OpticKind).
(Is k A_Fold, Monoid m, HasSingleIndex is i) =>
Optic' k is s a -> (i -> a -> m) -> s -> m
ifoldMapOf Optic' k is s a
o Key -> a -> IntMap a
forall (a :: OpticKind). Key -> a -> IntMap a
IntMap.singleton
{-# INLINE toMapOf #-}
lt :: Int -> IxAffineTraversal' Int (IntMap v) v
lt :: Key -> IxAffineTraversal' Key (IntMap v) v
lt Key
k = IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL (IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v)
-> IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Key -> v -> f v
f IntMap v
s ->
case Key -> IntMap v -> Maybe (Key, v)
forall (a :: OpticKind). Key -> IntMap a -> Maybe (Key, a)
IntMap.lookupLT Key
k IntMap v
s of
Maybe (Key, v)
Nothing -> IntMap v -> f (IntMap v)
forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Key
k', v
v) -> Key -> v -> f v
f Key
k' v
v f v -> (v -> IntMap v) -> f (IntMap v)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> Key -> v -> IntMap v -> IntMap v
forall (a :: OpticKind). Key -> a -> IntMap a -> IntMap a
IntMap.insert Key
k' v
v' IntMap v
s
{-# INLINE lt #-}
gt :: Int -> IxAffineTraversal' Int (IntMap v) v
gt :: Key -> IxAffineTraversal' Key (IntMap v) v
gt Key
k = IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL (IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v)
-> IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Key -> v -> f v
f IntMap v
s ->
case Key -> IntMap v -> Maybe (Key, v)
forall (a :: OpticKind). Key -> IntMap a -> Maybe (Key, a)
IntMap.lookupGT Key
k IntMap v
s of
Maybe (Key, v)
Nothing -> IntMap v -> f (IntMap v)
forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Key
k', v
v) -> Key -> v -> f v
f Key
k' v
v f v -> (v -> IntMap v) -> f (IntMap v)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> Key -> v -> IntMap v -> IntMap v
forall (a :: OpticKind). Key -> a -> IntMap a -> IntMap a
IntMap.insert Key
k' v
v' IntMap v
s
{-# INLINE gt #-}
le :: Int -> IxAffineTraversal' Int (IntMap v) v
le :: Key -> IxAffineTraversal' Key (IntMap v) v
le Key
k = IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL (IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v)
-> IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Key -> v -> f v
f IntMap v
s ->
case Key -> IntMap v -> Maybe (Key, v)
forall (a :: OpticKind). Key -> IntMap a -> Maybe (Key, a)
IntMap.lookupLE Key
k IntMap v
s of
Maybe (Key, v)
Nothing -> IntMap v -> f (IntMap v)
forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Key
k', v
v) -> Key -> v -> f v
f Key
k' v
v f v -> (v -> IntMap v) -> f (IntMap v)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> Key -> v -> IntMap v -> IntMap v
forall (a :: OpticKind). Key -> a -> IntMap a -> IntMap a
IntMap.insert Key
k' v
v' IntMap v
s
{-# INLINE le #-}
ge :: Int -> IxAffineTraversal' Int (IntMap v) v
ge :: Key -> IxAffineTraversal' Key (IntMap v) v
ge Key
k = IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL (IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v)
-> IxAffineTraversalVL Key (IntMap v) (IntMap v) v v
-> IxAffineTraversal' Key (IntMap v) v
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Key -> v -> f v
f IntMap v
s ->
case Key -> IntMap v -> Maybe (Key, v)
forall (a :: OpticKind). Key -> IntMap a -> Maybe (Key, a)
IntMap.lookupGE Key
k IntMap v
s of
Maybe (Key, v)
Nothing -> IntMap v -> f (IntMap v)
forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Key
k', v
v) -> Key -> v -> f v
f Key
k' v
v f v -> (v -> IntMap v) -> f (IntMap v)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> Key -> v -> IntMap v -> IntMap v
forall (a :: OpticKind). Key -> a -> IntMap a -> IntMap a
IntMap.insert Key
k' v
v' IntMap v
s
{-# INLINE ge #-}