@@ -27,21 +27,77 @@ import Data.Profunctor.Choice (class Choice)
27
27
import Data.Profunctor.Closed (class Closed )
28
28
import Data.Profunctor.Strong (class Strong )
29
29
30
- -- | A general-purpose Data.Lens.
31
- type Optic p s t a b = p a b -> p s t
32
- type Optic' p s a = Optic p s s a a
30
+ -- | Given a type whose "focus element" always exists,
31
+ -- | a lens provides a convenient way to view, set, and transform
32
+ -- | that element.
33
+ -- |
34
+ -- | For example, `_2` is a tuple-specific `Lens` available from `Data.Lens`, so:
35
+ -- | ```purescript
36
+ -- | over _2 String.length $ Tuple "ignore" "four" == Tuple "ignore" 4
37
+ -- | ```
38
+ -- | Note the result has a different type than the original tuple.
39
+ -- | That is, the four `Lens` type variables have been narrowed to:
40
+ -- |
41
+ -- | * `s` is `Tuple String String`
42
+ -- | * `t` is `Tuple String Int`
43
+ -- | * `a` is `String`
44
+ -- | * `b` is `Int`
45
+ -- |
46
+ -- | See `Data.Lens.Getter` and `Data.Lens.Setter` for functions and operators
47
+ -- | frequently used with lenses.
48
+
49
+
50
+ type Lens s t a b = forall p . Strong p => Optic p s t a b
51
+
52
+ -- | `Lens'` is a specialization of `Lens`. An optic of type `Lens'`
53
+ -- | can change only the value of its focus,
54
+ -- | not its type. As an example, consider the `Lens` `_2`, which has this type:
55
+ -- |
56
+ -- | ```purescript
57
+ -- | _2 :: forall s t a b. Lens (Tuple s a) (Tuple t b) a b
58
+ -- | ```
59
+ -- |
60
+ -- | `_2` can produce a `Tuple Int String` from a `Tuple Int Int`:
61
+ -- |
62
+ -- | ```purescript
63
+ -- | set _2 "NEW" (Tuple 1 2) == (Tuple 1 "NEW")
64
+ -- | ```
65
+ -- |
66
+ -- | If we specialize `_2`'s type with `Lens'`, the following will not
67
+ -- | type check:
68
+ -- |
69
+ -- | ```purescript
70
+ -- | set (_2 :: Lens' (Tuple Int Int) Int) "NEW" (Tuple 1 2)
71
+ -- | ^^^^^^^^^^^^^^^^^^^^^^^^^
72
+ -- | ```
73
+ -- |
74
+ -- | See `Data.Lens.Getter` and `Data.Lens.Setter` for functions and operators
75
+ -- | frequently used with lenses.
76
+
77
+ type Lens' s a = Lens s s a a
78
+
79
+ -- | A prism.
80
+ type Prism s t a b = forall p . Choice p => Optic p s t a b
81
+ type Prism' s a = Prism s s a a
33
82
34
83
-- | A generalized isomorphism.
35
84
type Iso s t a b = forall p . Profunctor p => Optic p s t a b
36
85
type Iso' s a = Iso s s a a
37
86
87
+ -- | A traversal.
88
+ type Traversal s t a b = forall p . Wander p => Optic p s t a b
89
+ type Traversal' s a = Traversal s s a a
90
+
91
+
92
+
93
+
94
+ -- | A general-purpose Data.Lens.
95
+ type Optic p s t a b = p a b -> p s t
96
+ type Optic' p s a = Optic p s s a a
97
+
38
98
type AnIso s t a b = Optic (Exchange a b ) s t a b
39
99
type AnIso' s a = AnIso s s a a
40
100
41
- -- | A lens.
42
- type Lens s t a b = forall p . Strong p => Optic p s t a b
43
- type Lens' s a = Lens s s a a
44
-
45
101
type ALens s t a b = Optic (Shop a b ) s t a b
46
102
type ALens' s a = ALens s s a a
47
103
@@ -52,17 +108,9 @@ type IndexedLens' i s a = IndexedLens i s s a a
52
108
type AnIndexedLens i s t a b = IndexedOptic (Shop (Tuple i a ) b ) i s t a b
53
109
type AnIndexedLens' i s a = AnIndexedLens i s s a a
54
110
55
- -- | A prism.
56
- type Prism s t a b = forall p . Choice p => Optic p s t a b
57
- type Prism' s a = Prism s s a a
58
-
59
111
type APrism s t a b = Optic (Market a b ) s t a b
60
112
type APrism' s a = APrism s s a a
61
113
62
- -- | A traversal.
63
- type Traversal s t a b = forall p . Wander p => Optic p s t a b
64
- type Traversal' s a = Traversal s s a a
65
-
66
114
-- | A grate (http://r6research.livejournal.com/28050.html)
67
115
type Grate s t a b = forall p . Closed p => Optic p s t a b
68
116
type Grate' s a = Grate s s a a
0 commit comments