@@ -4,16 +4,26 @@ module Data.Lens.Lens
4
4
, lens'
5
5
, withLens
6
6
, cloneLens
7
+ , ilens
8
+ , ilens'
9
+ , withIndexedLens
10
+ , cloneIndexedLens
7
11
, module Data.Lens.Types
8
12
) where
9
13
10
14
import Prelude
11
15
12
16
import Data.Lens.Internal.Shop (Shop (..))
13
- import Data.Lens.Types (Lens , Lens' , ALens , ALens' )
17
+ import Data.Lens.Internal.IndexedShop (IndexedShop (..))
18
+ import Data.Lens.Internal.Indexed (Indexed (..))
19
+ import Data.Lens.Types
20
+ ( Lens , Lens' , ALens , ALens'
21
+ , IndexedLens , IndexedLens' , AnIndexedLens , AnIndexedLens'
22
+ )
14
23
import Data.Profunctor (dimap )
15
24
import Data.Profunctor.Strong (first )
16
25
import Data.Tuple (Tuple (..))
26
+ import Data.Newtype (un )
17
27
18
28
lens' :: forall s t a b . (s -> Tuple a (b -> t )) -> Lens s t a b
19
29
lens' to pab = dimap to (\(Tuple b f) -> f b) (first pab)
@@ -27,3 +37,20 @@ withLens l f = case l (Shop id \_ b -> b) of Shop x y -> f x y
27
37
28
38
cloneLens :: forall s t a b . ALens s t a b -> Lens s t a b
29
39
cloneLens l = withLens l \x y p -> lens x y p
40
+
41
+
42
+ ilens' :: forall i s t a b .
43
+ (s -> Tuple (Tuple i a ) (b -> t )) -> IndexedLens i s t a b
44
+ ilens' to pab = dimap to (\(Tuple b f) -> f b) (first ((un Indexed ) pab))
45
+
46
+ -- create an `IndexedLens` from a getter/setter pair.
47
+ ilens :: forall i s t a b .
48
+ (s -> Tuple i a ) -> (s -> b -> t ) -> IndexedLens i s t a b
49
+ ilens get set = ilens' \s -> Tuple (get s) \b -> set s b
50
+
51
+ withIndexedLens :: forall i s t a b r .
52
+ (AnIndexedLens i s t a b ) -> ((s -> (Tuple i a )) -> (s -> b -> t ) -> r ) -> r
53
+ withIndexedLens l f = case l (Indexed (IndexedShop id \_ b -> b)) of IndexedShop x y -> f x y
54
+
55
+ cloneIndexedLens :: forall i s t a b . AnIndexedLens i s t a b -> IndexedLens i s t a b
56
+ cloneIndexedLens l = withIndexedLens l \x y p -> ilens x y p
0 commit comments