@@ -9,27 +9,46 @@ class Profunctor p where
9
9
dimap :: forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
10
10
```
11
11
12
+ A ` Profunctor ` is a ` Functor ` from the pair category ` (Type^op, Type) `
13
+ to ` Type ` .
14
+
15
+ In other words, a ` Profunctor ` is a type constructor of two type
16
+ arguments, which is contravariant in its first argument and covariant
17
+ in its second argument.
18
+
19
+ The ` dimap ` function can be used to map functions over both arguments
20
+ simultaneously.
21
+
22
+ A straightforward example of a profunctor is the function arrow ` (->) ` .
23
+
24
+ Laws:
25
+
26
+ - Identity: ` dimap id id = id `
27
+ - Composition: ` dimap f1 g1 <<< dimap f2 g2 = dimap (f1 >>> f2) (g1 <<< g2) `
12
28
13
29
#### ` lmap `
14
30
15
31
``` purescript
16
32
lmap :: forall a b c p. (Profunctor p) => (a -> b) -> p b c -> p a c
17
33
```
18
34
35
+ Map a function over the (contravariant) first type argument only.
19
36
20
37
#### ` rmap `
21
38
22
39
``` purescript
23
40
rmap :: forall a b c p. (Profunctor p) => (b -> c) -> p a b -> p a c
24
41
```
25
42
43
+ Map a function over the (covariant) second type argument only.
26
44
27
45
#### ` arr `
28
46
29
47
``` purescript
30
48
arr :: forall a b p. (Category p, Profunctor p) => (a -> b) -> p a b
31
49
```
32
50
51
+ Lift a pure function into any ` Profunctor ` which is also a ` Category ` .
33
52
34
53
#### ` profunctorArr `
35
54
@@ -49,6 +68,12 @@ class (Profunctor p) <= Choice p where
49
68
right :: forall a b c. p b c -> p (Either a b) (Either a c)
50
69
```
51
70
71
+ The ` Choice ` class extends ` Profunctor ` with combinators for working with
72
+ sum types.
73
+
74
+ ` left ` and ` right ` lift values in a ` Profunctor ` to act on the ` Left ` and
75
+ ` Right ` components of a sum, respectively.
76
+
52
77
53
78
#### ` choiceArr `
54
79
@@ -63,13 +88,20 @@ instance choiceArr :: Choice Prim.Function
63
88
(+++) :: forall p a b c d. (Category p, Choice p) => p a b -> p c d -> p (Either a c) (Either b d)
64
89
```
65
90
91
+ Compose a value acting on a sum from two values, each acting on one of
92
+ the components of the sum.
66
93
67
94
#### ` (|||) `
68
95
69
96
``` purescript
70
97
(|||) :: forall p a b c. (Category p, Choice p) => p a c -> p b c -> p (Either a b) c
71
98
```
72
99
100
+ Compose a value which eliminates a sum from two values, each eliminating
101
+ one side of the sum.
102
+
103
+ This combinator is useful when assembling values from smaller components,
104
+ because it provides a way to support two different types of input.
73
105
74
106
75
107
## Module Data.Profunctor.Strong
@@ -82,6 +114,12 @@ class (Profunctor p) <= Strong p where
82
114
second :: forall a b c. p b c -> p (Tuple a b) (Tuple a c)
83
115
```
84
116
117
+ The ` Strong ` class extends ` Profunctor ` with combinators for working with
118
+ product types.
119
+
120
+ ` first ` and ` first ` lift values in a ` Profunctor ` to act on the first and
121
+ second components of a ` Tuple ` , respectively.
122
+
85
123
86
124
#### ` strongArr `
87
125
@@ -96,9 +134,17 @@ instance strongArr :: Strong Prim.Function
96
134
(***) :: forall p a b c d. (Category p, Strong p) => p a b -> p c d -> p (Tuple a c) (Tuple b d)
97
135
```
98
136
137
+ Compose a value acting on a ` Tuple ` from two values, each acting on one of
138
+ the components of the ` Tuple ` .
99
139
100
140
#### ` (&&&) `
101
141
102
142
``` purescript
103
143
(&&&) :: forall p a b c. (Category p, Strong p) => p a b -> p a c -> p a (Tuple b c)
104
- ```
144
+ ```
145
+
146
+ Compose a value which introduces a ` Tuple ` from two values, each introducing
147
+ one side of the ` Tuple ` .
148
+
149
+ This combinator is useful when assembling values from smaller components,
150
+ because it provides a way to support two different types of output.
0 commit comments