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