| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Optics.At
Description
This module provides optics for Map and Set-like
containers, including an AffineTraversal to traverse a key in a map or an
element of a sequence:
>>>preview (ix 1) ['a','b','c']Just 'b'
a Lens to get, set or delete a key in a map:
>>>set (at 0) (Just 'b') (Map.fromList [(0, 'a')])fromList [(0,'b')]
and a Lens to insert or remove an element of a set:
>>>IntSet.fromList [1,2,3,4] & contains 3 .~ FalsefromList [1,2,4]
This module includes the core definitions from Optics.At.Core along with extra (orphan) instances.
Type families
Type family that takes a key-value container type and returns the type of
keys (indices) into the container, for example .
This is shared by Index (Map k a) ~ kIxed, At and Contains.
Instances
| type Index ByteString Source # | |
Defined in Optics.At | |
| type Index ByteString Source # | |
Defined in Optics.At | |
| type Index IntSet | |
Defined in Optics.At.Core | |
| type Index Text Source # | |
| type Index Text Source # | |
| type Index [a] | |
Defined in Optics.At.Core | |
| type Index (Maybe a) | |
Defined in Optics.At.Core | |
| type Index (Complex a) | |
Defined in Optics.At.Core | |
| type Index (Identity a) | |
Defined in Optics.At.Core | |
| type Index (NonEmpty a) | |
Defined in Optics.At.Core | |
| type Index (IntMap a) | |
Defined in Optics.At.Core | |
| type Index (Tree a) | |
Defined in Optics.At.Core | |
| type Index (Seq a) | |
Defined in Optics.At.Core | |
| type Index (Set a) | |
Defined in Optics.At.Core | |
| type Index (HashSet a) Source # | |
| type Index (Vector a) Source # | |
| type Index (Vector a) Source # | |
| type Index (Vector a) Source # | |
| type Index (Vector a) Source # | |
| type Index (e -> a) | |
Defined in Optics.At.Core type Index (e -> a) = e | |
| type Index (a, b) | |
Defined in Optics.At.Core | |
| type Index (UArray i e) | |
Defined in Optics.At.Core | |
| type Index (Array i e) | |
Defined in Optics.At.Core | |
| type Index (Map k a) | |
Defined in Optics.At.Core | |
| type Index (HashMap k a) Source # | |
| type Index (a, b, c) | |
Defined in Optics.At.Core | |
| type Index (a, b, c, d) | |
Defined in Optics.At.Core | |
| type Index (a, b, c, d, e) | |
Defined in Optics.At.Core | |
| type Index (a, b, c, d, e, f) | |
Defined in Optics.At.Core | |
| type Index (a, b, c, d, e, f, g) | |
Defined in Optics.At.Core | |
| type Index (a, b, c, d, e, f, g, h) | |
Defined in Optics.At.Core | |
| type Index (a, b, c, d, e, f, g, h, i) | |
Defined in Optics.At.Core | |
Type family that takes a key-value container type and returns the type of
values stored in the container, for example . This
is shared by both IxValue (Map k a) ~ aIxed and At.
Instances
| type IxValue ByteString Source # | |
Defined in Optics.At | |
| type IxValue ByteString Source # | |
Defined in Optics.At | |
| type IxValue IntSet | |
Defined in Optics.At.Core | |
| type IxValue Text Source # | |
| type IxValue Text Source # | |
| type IxValue [a] | |
Defined in Optics.At.Core type IxValue [a] = a | |
| type IxValue (Maybe a) | |
Defined in Optics.At.Core | |
| type IxValue (Identity a) | |
Defined in Optics.At.Core | |
| type IxValue (NonEmpty a) | |
Defined in Optics.At.Core | |
| type IxValue (IntMap a) | |
Defined in Optics.At.Core | |
| type IxValue (Tree a) | |
Defined in Optics.At.Core | |
| type IxValue (Seq a) | |
Defined in Optics.At.Core | |
| type IxValue (Set k) | |
Defined in Optics.At.Core | |
| type IxValue (HashSet k) Source # | |
| type IxValue (Vector a) Source # | |
| type IxValue (Vector a) Source # | |
| type IxValue (Vector a) Source # | |
| type IxValue (Vector a) Source # | |
| type IxValue (e -> a) | |
Defined in Optics.At.Core type IxValue (e -> a) = a | |
| type IxValue (a0, a2) |
|
Defined in Optics.At.Core type IxValue (a0, a2) = a0 | |
| type IxValue (UArray i e) | |
Defined in Optics.At.Core | |
| type IxValue (Array i e) | |
Defined in Optics.At.Core | |
| type IxValue (Map k a) | |
Defined in Optics.At.Core | |
| type IxValue (HashMap k a) Source # | |
| type IxValue (a0, a1, a2) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2) = a0 | |
| type IxValue (a0, a1, a2, a3) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2, a3) = a0 | |
| type IxValue (a0, a1, a2, a3, a4) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2, a3, a4) = a0 | |
| type IxValue (a0, a1, a2, a3, a4, a5) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2, a3, a4, a5) = a0 | |
| type IxValue (a0, a1, a2, a3, a4, a5, a6) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2, a3, a4, a5, a6) = a0 | |
| type IxValue (a0, a1, a2, a3, a4, a5, a6, a7) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2, a3, a4, a5, a6, a7) = a0 | |
| type IxValue (a0, a1, a2, a3, a4, a5, a6, a7, a8) |
|
Defined in Optics.At.Core type IxValue (a0, a1, a2, a3, a4, a5, a6, a7, a8) = a0 | |
Ixed
Provides a simple AffineTraversal lets you traverse the value at a given
key in a Map or element at an ordinal position in a list or Seq.
Minimal complete definition
Nothing
Associated Types
Type family that takes a key-value container type and returns the kind
of optic to index into it. For most containers, it's An_AffineTraversal,
Representable (Naperian) containers it is A_Lens, and multi-maps would
have A_Traversal.
type IxKind m = An_AffineTraversal
Methods
ix :: Index m -> Optic' (IxKind m) NoIx m (IxValue m) #
NB: Setting the value of this AffineTraversal 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.
>>>[1,2,3,4] & ix 2 %~ (*10)[1,2,30,4]
>>>"abcd" & ix 2 .~ 'e'"abed"
>>>"abcd" ^? ix 2Just 'c'
>>>[] ^? ix 2Nothing
Instances
| Ixed ByteString Source # | |
Defined in Optics.At Associated Types type IxKind ByteString # Methods ix :: Index ByteString -> Optic' (IxKind ByteString) NoIx ByteString (IxValue ByteString) # | |
| Ixed ByteString Source # | |
Defined in Optics.At Associated Types type IxKind ByteString # Methods ix :: Index ByteString -> Optic' (IxKind ByteString) NoIx ByteString (IxValue ByteString) # | |
| Ixed IntSet | |
| Ixed Text Source # | |
| Ixed Text Source # | |
| Ixed [a] | |
| Ixed (Maybe a) | |
| Ixed (Identity a) | |
| Ixed (NonEmpty a) | |
| Ixed (IntMap a) | |
| Ixed (Tree a) | |
| Ixed (Seq a) | |
| Ord k => Ixed (Set k) | |
| (Eq k, Hashable k) => Ixed (HashSet k) Source # | |
| Unbox a => Ixed (Vector a) Source # | |
| Storable a => Ixed (Vector a) Source # | |
| Prim a => Ixed (Vector a) Source # | |
| Ixed (Vector a) Source # | |
| Eq e => Ixed (e -> a) | |
| a0 ~ a1 => Ixed (a0, a1) | |
| (IArray UArray e, Ix i) => Ixed (UArray i e) | arr |
| Ix i => Ixed (Array i e) | arr |
| Ord k => Ixed (Map k a) | |
| (Eq k, Hashable k) => Ixed (HashMap k a) Source # | |
| (a0 ~ a1, a0 ~ a2) => Ixed (a0, a1, a2) | |
| (a0 ~ a1, a0 ~ a2, a0 ~ a3) => Ixed (a0, a1, a2, a3) | |
| (a0 ~ a1, a0 ~ a2, a0 ~ a3, a0 ~ a4) => Ixed (a0, a1, a2, a3, a4) | |
| (a0 ~ a1, a0 ~ a2, a0 ~ a3, a0 ~ a4, a0 ~ a5) => Ixed (a0, a1, a2, a3, a4, a5) | |
| (a0 ~ a1, a0 ~ a2, a0 ~ a3, a0 ~ a4, a0 ~ a5, a0 ~ a6) => Ixed (a0, a1, a2, a3, a4, a5, a6) | |
| (a0 ~ a1, a0 ~ a2, a0 ~ a3, a0 ~ a4, a0 ~ a5, a0 ~ a6, a0 ~ a7) => Ixed (a0, a1, a2, a3, a4, a5, a6, a7) | |
| (a0 ~ a1, a0 ~ a2, a0 ~ a3, a0 ~ a4, a0 ~ a5, a0 ~ a6, a0 ~ a7, a0 ~ a8) => Ixed (a0, a1, a2, a3, a4, a5, a6, a7, a8) | |
At
class (Ixed m, IxKind m ~ An_AffineTraversal) => At m where #
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:
ixk ≡atk%_Just
Methods
at :: Index m -> Lens' m (Maybe (IxValue m)) #
>>>Map.fromList [(1,"world")] ^. at 1Just "world"
>>>at 1 ?~ "hello" $ Map.emptyfromList [(1,"hello")]
Note: Usage of this function might introduce space leaks if you're not
careful to make sure that values put inside the Just constructor are
evaluated. To force the values and avoid such leaks, use at' instead.
Note: Map-like containers form a reasonable instance, but not
Array-like ones, where you cannot satisfy the Lens laws.
at' :: At m => Index m -> Lens' m (Maybe (IxValue m)) #
Version of at strict in the value inside the Just constructor.
Example:
>>>(at () .~ Just (error "oops") $ Nothing) `seq` ()()
>>>(at' () .~ Just (error "oops") $ Nothing) `seq` ()*** Exception: oops ...
>>>view (at ()) (Just $ error "oops") `seq` ()()
>>>view (at' ()) (Just $ error "oops") `seq` ()*** Exception: oops ...
It also works as expected for other data structures:
>>>(at 1 .~ Just (error "oops") $ Map.empty) `seq` ()()
>>>(at' 1 .~ Just (error "oops") $ Map.empty) `seq` ()*** Exception: oops ...
Contains
This class provides a simple Lens that lets you view (and modify)
information about whether or not a container contains a given Index.
Instances are provided for Set-like containers only.
Methods
contains :: Index m -> Lens' m Bool #
>>>IntSet.fromList [1,2,3,4] ^. contains 3True
>>>IntSet.fromList [1,2,3,4] ^. contains 5False
>>>IntSet.fromList [1,2,3,4] & contains 3 .~ FalsefromList [1,2,4]
Orphan instances
| Ixed ByteString Source # | |
Associated Types type IxKind ByteString # Methods ix :: Index ByteString -> Optic' (IxKind ByteString) NoIx ByteString (IxValue ByteString) # | |
| Ixed ByteString Source # | |
Associated Types type IxKind ByteString # Methods ix :: Index ByteString -> Optic' (IxKind ByteString) NoIx ByteString (IxValue ByteString) # | |
| Ixed Text Source # | |
| Ixed Text Source # | |
| (Eq a, Hashable a) => Contains (HashSet a) Source # | |
| (Eq k, Hashable k) => Ixed (HashSet k) Source # | |
| Unbox a => Ixed (Vector a) Source # | |
| Storable a => Ixed (Vector a) Source # | |
| Prim a => Ixed (Vector a) Source # | |
| Ixed (Vector a) Source # | |
| (Eq k, Hashable k) => At (HashSet k) Source # | |
| (Eq k, Hashable k) => Ixed (HashMap k a) Source # | |
| (Eq k, Hashable k) => At (HashMap k a) Source # | |