Copyright | (C) 2012-16 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Synopsis
- class Ixed m => At m where
- sans :: At m => Index m -> m -> m
- iat :: At m => Index m -> IndexedLens' (Index m) m (Maybe (IxValue m))
- type family Index (s :: Type) :: Type
- type family IxValue (m :: Type) :: Type
- class Ixed m where
- ix :: Index m -> Traversal' m (IxValue m)
- ixAt :: At m => Index m -> Traversal' m (IxValue m)
- iix :: Ixed m => Index m -> IndexedTraversal' (Index m) m (IxValue m)
- class Contains m where
- icontains :: Contains m => Index m -> IndexedLens' (Index m) m Bool
At
class Ixed m => At m where Source #
At
provides a Lens
that can be used to read,
write or delete the value associated with a key in a Map
-like
container on an ad hoc basis.
An instance of At
should satisfy:
ix
k ≡at
k.
traverse
iat :: At m => Index m -> IndexedLens' (Index m) m (Maybe (IxValue m)) Source #
An indexed version of at
.
>>>
Map.fromList [(1,"world")] ^@. iat 1
(1,Just "world")
>>>
iat 1 %@~ (\i x -> if odd i then Just "hello" else Nothing) $ Map.empty
fromList [(1,"hello")]
>>>
iat 2 %@~ (\i x -> if odd i then Just "hello" else Nothing) $ Map.empty
fromList []
Ixed
type family Index (s :: Type) :: Type Source #
Instances
type family IxValue (m :: Type) :: Type Source #
Instances
type IxValue ByteString Source # | |
Defined in Control.Lens.At | |
type IxValue ByteString Source # | |
Defined in Control.Lens.At | |
type IxValue IntSet Source # | |
Defined in Control.Lens.At | |
type IxValue Text Source # | |
Defined in Control.Lens.At | |
type IxValue Text Source # | |
Defined in Control.Lens.At | |
type IxValue (Identity a) Source # | |
Defined in Control.Lens.At | |
type IxValue (NonEmpty a) Source # | |
Defined in Control.Lens.At | |
type IxValue (IntMap a) Source # | |
Defined in Control.Lens.At | |
type IxValue (Seq a) Source # | |
Defined in Control.Lens.At | |
type IxValue (Set k) Source # | |
Defined in Control.Lens.At | |
type IxValue (Tree a) Source # | |
Defined in Control.Lens.At | |
type IxValue (HashSet k) Source # | |
Defined in Control.Lens.At | |
type IxValue (Vector a) Source # | |
Defined in Control.Lens.At | |
type IxValue (Vector a) Source # | |
Defined in Control.Lens.At | |
type IxValue (Vector a) Source # | |
Defined in Control.Lens.At | |
type IxValue (Vector a) Source # | |
Defined in Control.Lens.At | |
type IxValue (Maybe a) Source # | |
Defined in Control.Lens.At | |
type IxValue [a] Source # | |
Defined in Control.Lens.At type IxValue [a] = a | |
type IxValue (UArray i e) Source # | |
Defined in Control.Lens.At | |
type IxValue (Array i e) Source # | |
Defined in Control.Lens.At | |
type IxValue (Map k a) Source # | |
Defined in Control.Lens.At | |
type IxValue (HashMap k a) Source # | |
Defined in Control.Lens.At | |
type IxValue (a, a2) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2) = a | |
type IxValue (e -> a) Source # | |
Defined in Control.Lens.At type IxValue (e -> a) = a | |
type IxValue (a, a2, a3) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3) = a | |
type IxValue (a, a2, a3, a4) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3, a4) = a | |
type IxValue (a, a2, a3, a4, a5) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3, a4, a5) = a | |
type IxValue (a, a2, a3, a4, a5, a6) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3, a4, a5, a6) = a | |
type IxValue (a, a2, a3, a4, a5, a6, a7) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3, a4, a5, a6, a7) = a | |
type IxValue (a, a2, a3, a4, a5, a6, a7, a8) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3, a4, a5, a6, a7, a8) = a | |
type IxValue (a, a2, a3, a4, a5, a6, a7, a8, a9) Source # |
|
Defined in Control.Lens.At type IxValue (a, a2, a3, a4, a5, a6, a7, a8, a9) = a |
Provides a simple Traversal
lets you traverse
the value at a given
key in a Map
or element at an ordinal position in a list or Seq
.
Nothing
ix :: Index m -> Traversal' m (IxValue m) Source #
NB: Setting the value of this Traversal
will only set the value in
at
if it is already present.
If you want to be able to insert missing values, you want at
.
>>>
Seq.fromList [a,b,c,d] & ix 2 %~ f
fromList [a,b,f c,d]
>>>
Seq.fromList [a,b,c,d] & ix 2 .~ e
fromList [a,b,e,d]
>>>
Seq.fromList [a,b,c,d] ^? ix 2
Just c
>>>
Seq.fromList [] ^? ix 2
Nothing
Instances
Ixed ByteString Source # | |
Defined in Control.Lens.At ix :: Index ByteString -> Traversal' ByteString (IxValue ByteString) Source # | |
Ixed ByteString Source # | |
Defined in Control.Lens.At ix :: Index ByteString -> Traversal' ByteString (IxValue ByteString) Source # | |
Ixed IntSet Source # | |
Defined in Control.Lens.At | |
Ixed Text Source # | |
Defined in Control.Lens.At | |
Ixed Text Source # | |
Defined in Control.Lens.At | |
Ixed (Identity a) Source # | |
Defined in Control.Lens.At | |
Ixed (NonEmpty a) Source # | |
Defined in Control.Lens.At | |
Ixed (IntMap a) Source # | |
Defined in Control.Lens.At | |
Ixed (Seq a) Source # | |
Defined in Control.Lens.At | |
Ord k => Ixed (Set k) Source # | |
Defined in Control.Lens.At | |
Ixed (Tree a) Source # | |
Defined in Control.Lens.At | |
(Eq k, Hashable k) => Ixed (HashSet k) Source # | |
Defined in Control.Lens.At | |
Ixed (Vector a) Source # | |
Defined in Control.Lens.At | |
Prim a => Ixed (Vector a) Source # | |
Defined in Control.Lens.At | |
Storable a => Ixed (Vector a) Source # | |
Defined in Control.Lens.At | |
Unbox a => Ixed (Vector a) Source # | |
Defined in Control.Lens.At | |
Ixed (Maybe a) Source # | |
Defined in Control.Lens.At | |
Ixed [a] Source # | |
Defined in Control.Lens.At | |
(IArray UArray e, Ix i) => Ixed (UArray i e) Source # | arr |
Defined in Control.Lens.At | |
Ix i => Ixed (Array i e) Source # | arr |
Defined in Control.Lens.At | |
Ord k => Ixed (Map k a) Source # | |
Defined in Control.Lens.At | |
(Eq k, Hashable k) => Ixed (HashMap k a) Source # | |
Defined in Control.Lens.At | |
a ~ a2 => Ixed (a, a2) Source # | |
Defined in Control.Lens.At | |
Eq e => Ixed (e -> a) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3) => Ixed (a, a2, a3) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3, a ~ a4) => Ixed (a, a2, a3, a4) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3, a ~ a4, a ~ a5) => Ixed (a, a2, a3, a4, a5) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6) => Ixed (a, a2, a3, a4, a5, a6) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7) => Ixed (a, a2, a3, a4, a5, a6, a7) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8) => Ixed (a, a2, a3, a4, a5, a6, a7, a8) Source # | |
Defined in Control.Lens.At | |
(a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, a ~ a9) => Ixed (a, a2, a3, a4, a5, a6, a7, a8, a9) Source # | |
Defined in Control.Lens.At |
iix :: Ixed m => Index m -> IndexedTraversal' (Index m) m (IxValue m) Source #
An indexed version of ix
.
>>>
Seq.fromList [a,b,c,d] & iix 2 %@~ f'
fromList [a,b,f' 2 c,d]
>>>
Seq.fromList [a,b,c,d] & iix 2 .@~ h
fromList [a,b,h 2,d]
>>>
Seq.fromList [a,b,c,d] ^@? iix 2
Just (2,c)
>>>
Seq.fromList [] ^@? iix 2
Nothing
Contains
class Contains m where Source #
This class provides a simple Lens
that lets you view (and modify)
information about whether or not a container contains a given Index
.
contains :: Index m -> Lens' m Bool Source #
>>>
IntSet.fromList [1,2,3,4] ^. contains 3
True
>>>
IntSet.fromList [1,2,3,4] ^. contains 5
False
>>>
IntSet.fromList [1,2,3,4] & contains 3 .~ False
fromList [1,2,4]
icontains :: Contains m => Index m -> IndexedLens' (Index m) m Bool Source #
An indexed version of contains
.
>>>
IntSet.fromList [1,2,3,4] ^@. icontains 3
(3,True)
>>>
IntSet.fromList [1,2,3,4] ^@. icontains 5
(5,False)
>>>
IntSet.fromList [1,2,3,4] & icontains 3 %@~ \i x -> if odd i then not x else x
fromList [1,2,4]
>>>
IntSet.fromList [1,2,3,4] & icontains 3 %@~ \i x -> if even i then not x else x
fromList [1,2,3,4]