{-# 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 :: forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(a :: OpticKind).
(Is k A_Fold, HasSingleIndex is Int) =>
Optic' k is s a -> s -> IntMap a
toMapOf Optic' k is s a
o = 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 forall (a :: OpticKind). Int -> a -> IntMap a
IntMap.singleton
{-# INLINE toMapOf #-}
lt :: Int -> IxAffineTraversal' Int (IntMap v) v
lt :: forall (v :: OpticKind). Int -> IxAffineTraversal' Int (IntMap v) v
lt Int
k = forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Int -> v -> f v
f IntMap v
s ->
case forall (a :: OpticKind). Int -> IntMap a -> Maybe (Int, a)
IntMap.lookupLT Int
k IntMap v
s of
Maybe (Int, v)
Nothing -> forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Int
k', v
v) -> Int -> v -> f v
f Int
k' v
v forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> forall (a :: OpticKind). Int -> a -> IntMap a -> IntMap a
IntMap.insert Int
k' v
v' IntMap v
s
{-# INLINE lt #-}
gt :: Int -> IxAffineTraversal' Int (IntMap v) v
gt :: forall (v :: OpticKind). Int -> IxAffineTraversal' Int (IntMap v) v
gt Int
k = forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Int -> v -> f v
f IntMap v
s ->
case forall (a :: OpticKind). Int -> IntMap a -> Maybe (Int, a)
IntMap.lookupGT Int
k IntMap v
s of
Maybe (Int, v)
Nothing -> forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Int
k', v
v) -> Int -> v -> f v
f Int
k' v
v forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> forall (a :: OpticKind). Int -> a -> IntMap a -> IntMap a
IntMap.insert Int
k' v
v' IntMap v
s
{-# INLINE gt #-}
le :: Int -> IxAffineTraversal' Int (IntMap v) v
le :: forall (v :: OpticKind). Int -> IxAffineTraversal' Int (IntMap v) v
le Int
k = forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Int -> v -> f v
f IntMap v
s ->
case forall (a :: OpticKind). Int -> IntMap a -> Maybe (Int, a)
IntMap.lookupLE Int
k IntMap v
s of
Maybe (Int, v)
Nothing -> forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Int
k', v
v) -> Int -> v -> f v
f Int
k' v
v forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> forall (a :: OpticKind). Int -> a -> IntMap a -> IntMap a
IntMap.insert Int
k' v
v' IntMap v
s
{-# INLINE le #-}
ge :: Int -> IxAffineTraversal' Int (IntMap v) v
ge :: forall (v :: OpticKind). Int -> IxAffineTraversal' Int (IntMap v) v
ge Int
k = forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \forall (r :: OpticKind). r -> f r
point Int -> v -> f v
f IntMap v
s ->
case forall (a :: OpticKind). Int -> IntMap a -> Maybe (Int, a)
IntMap.lookupGE Int
k IntMap v
s of
Maybe (Int, v)
Nothing -> forall (r :: OpticKind). r -> f r
point IntMap v
s
Just (Int
k', v
v) -> Int -> v -> f v
f Int
k' v
v forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
f a -> (a -> b) -> f b
<&> \v
v' -> forall (a :: OpticKind). Int -> a -> IntMap a -> IntMap a
IntMap.insert Int
k' v
v' IntMap v
s
{-# INLINE ge #-}