Skip to content

Commit db82fe8

Browse files
committed
Merge pull request #5 from zrho/master
Wander, some Folds and ALens; corrected.
2 parents c111b3d + 9f85358 commit db82fe8

File tree

22 files changed

+538
-27
lines changed

22 files changed

+538
-27
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"purescript-const": "~0.5.0",
2222
"purescript-identity": "~0.4.0",
2323
"purescript-profunctor": "~0.3.0",
24-
"purescript-lists": "~0.7.0"
24+
"purescript-lists": "~0.7.0",
25+
"purescript-unsafe-coerce": "~0.1.0"
2526
}
2627
}

docs/Data/Lens.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ This module re-exports types and functions from other modules:
1010
- [`module Data.Lens.Setter`](Lens/Setter.md)
1111
- [`module Data.Lens.Getter`](Lens/Getter.md)
1212
- [`module Data.Lens.Fold`](Lens/Fold.md)
13+
- [`module Data.Lens.Common`](Lens/Common.md)
1314

1415

docs/Data/Lens/Common.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Module Data.Lens.Common
2+
3+
This module defines common lenses and prisms.
4+
5+
#### `_Nothing`
6+
7+
``` purescript
8+
_Nothing :: forall a b. Prism (Maybe a) (Maybe b) Unit Unit
9+
```
10+
11+
#### `_Just`
12+
13+
``` purescript
14+
_Just :: forall a b. Prism (Maybe a) (Maybe b) a b
15+
```
16+
17+
Prism for the `Just` constructor of `Maybe`.
18+
19+
#### `_Left`
20+
21+
``` purescript
22+
_Left :: forall a b c. Prism (Either a c) (Either b c) a b
23+
```
24+
25+
Prism for the `Left` constructor of `Either`.
26+
27+
#### `_Right`
28+
29+
``` purescript
30+
_Right :: forall a b c. Prism (Either c a) (Either c b) a b
31+
```
32+
33+
Prism for the `Right` constructor of `Either`.
34+
35+
#### `_1`
36+
37+
``` purescript
38+
_1 :: forall a b c. Lens (Tuple a c) (Tuple b c) a b
39+
```
40+
41+
Lens for the first component of a `Tuple`.
42+
43+
#### `_2`
44+
45+
``` purescript
46+
_2 :: forall a b c. Lens (Tuple c a) (Tuple c b) a b
47+
```
48+
49+
Lens for the second component of a `Tuple`.
50+
51+
#### `united`
52+
53+
``` purescript
54+
united :: forall a. LensP a Unit
55+
```
56+
57+
There is a `Unit` in everything.
58+
59+
#### `devoid`
60+
61+
``` purescript
62+
devoid :: forall a. LensP Void a
63+
```
64+
65+
There is everything in `Void`.
66+
67+

docs/Data/Lens/Fold.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,127 @@ foldlOf :: forall s t a b r. Fold (Dual (Endo r)) s t a b -> (r -> a -> r) -> r
5252

5353
Left fold over a `Fold`.
5454

55+
#### `allOf`
56+
57+
``` purescript
58+
allOf :: forall s t a b r. (BooleanAlgebra r) => Fold (Conj r) s t a b -> (a -> r) -> s -> r
59+
```
60+
61+
Whether all foci of a `Fold` satisfy a predicate.
62+
63+
#### `anyOf`
64+
65+
``` purescript
66+
anyOf :: forall s t a b r. (BooleanAlgebra r) => Fold (Disj r) s t a b -> (a -> r) -> s -> r
67+
```
68+
69+
Whether any focus of a `Fold` satisfies a predicate.
70+
71+
#### `andOf`
72+
73+
``` purescript
74+
andOf :: forall s t a b. (BooleanAlgebra a) => Fold (Conj a) s t a b -> s -> a
75+
```
76+
77+
The conjunction of all foci of a `Fold`.
78+
79+
#### `orOf`
80+
81+
``` purescript
82+
orOf :: forall s t a b. (BooleanAlgebra a) => Fold (Disj a) s t a b -> s -> a
83+
```
84+
85+
The disjunction of all foci of a `Fold`.
86+
87+
#### `elemOf`
88+
89+
``` purescript
90+
elemOf :: forall s t a b. (Eq a) => Fold (Disj Boolean) s t a b -> a -> s -> Boolean
91+
```
92+
93+
Whether a `Fold` contains a given element.
94+
95+
#### `notElemOf`
96+
97+
``` purescript
98+
notElemOf :: forall s t a b. (Eq a) => Fold (Conj Boolean) s t a b -> a -> s -> Boolean
99+
```
100+
101+
Whether a `Fold` not contains a given element.
102+
103+
#### `sumOf`
104+
105+
``` purescript
106+
sumOf :: forall s t a b. (Semiring a) => Fold (Additive a) s t a b -> s -> a
107+
```
108+
109+
The sum of all foci of a `Fold`.
110+
111+
#### `productOf`
112+
113+
``` purescript
114+
productOf :: forall s t a b. (Semiring a) => Fold (Multiplicative a) s t a b -> s -> a
115+
```
116+
117+
The product of all foci of a `Fold`.
118+
119+
#### `lengthOf`
120+
121+
``` purescript
122+
lengthOf :: forall s t a b. Fold (Additive Int) s t a b -> s -> Int
123+
```
124+
125+
The number of foci of a `Fold`.
126+
127+
#### `firstOf`
128+
129+
``` purescript
130+
firstOf :: forall s t a b. Fold (First a) s t a b -> s -> Maybe a
131+
```
132+
133+
The first focus of a `Fold`, if there is any. Synonym for `preview`.
134+
135+
#### `lastOf`
136+
137+
``` purescript
138+
lastOf :: forall s t a b. Fold (Last a) s t a b -> s -> Maybe a
139+
```
140+
141+
The last focus of a `Fold`, if there is any.
142+
143+
#### `maximumOf`
144+
145+
``` purescript
146+
maximumOf :: forall s t a b. (Ord a) => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
147+
```
148+
149+
The maximum of all foci of a `Fold`, if there is any.
150+
151+
#### `minimumOf`
152+
153+
``` purescript
154+
minimumOf :: forall s t a b. (Ord a) => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
155+
```
156+
157+
The minimum of all foci of a `Fold`, if there is any.
158+
159+
#### `findOf`
160+
161+
``` purescript
162+
findOf :: forall s t a b. Fold (Endo (Maybe a)) s t a b -> (a -> Boolean) -> s -> Maybe a
163+
```
164+
165+
Find the first focus of a `Fold` that satisfies a predicate, if there is any.
166+
167+
#### `sequenceOf_`
168+
169+
``` purescript
170+
sequenceOf_ :: forall f s t a b. (Applicative f) => Fold (Endo (f Unit)) s t (f a) b -> s -> f Unit
171+
```
172+
173+
Sequence the foci of a `Fold`, pulling out an `Applicative`, and ignore
174+
the result. If you need the result, see `sequenceOf` for `Traversal`s.
175+
55176
#### `toListOf`
56177

57178
``` purescript
@@ -86,4 +207,20 @@ hasn't :: forall s t a b r. (BooleanAlgebra r) => Fold (Conj r) s t a b -> s ->
86207

87208
Determines whether a `Fold` does not have a focus.
88209

210+
#### `filtered`
211+
212+
``` purescript
213+
filtered :: forall p a. (Choice p) => (a -> Boolean) -> OpticP p a a
214+
```
215+
216+
Filters on a predicate.
217+
218+
#### `replicated`
219+
220+
``` purescript
221+
replicated :: forall r a b t f. (Applicative f, Contravariant f) => Int -> Optic (Star f) a b a t
222+
```
223+
224+
Replicates the elements of a fold.
225+
89226

docs/Data/Lens/Internal/Shop.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Module Data.Lens.Internal.Shop
2+
3+
This module defines the `Shop` profunctor
4+
5+
#### `Shop`
6+
7+
``` purescript
8+
data Shop a b s t
9+
= Shop (s -> a) (s -> b -> t)
10+
```
11+
12+
The `Shop` profunctor characterizes a `Lens`.
13+
14+
##### Instances
15+
``` purescript
16+
instance profunctorShop :: Profunctor (Shop a b)
17+
instance strongShop :: Strong (Shop a b)
18+
```
19+
20+

docs/Data/Lens/Internal/Void.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Module Data.Lens.Internal.Void
2+
3+
This module defines the empty `Void` type.
4+
5+
#### `Void`
6+
7+
``` purescript
8+
data Void
9+
```
10+
11+
#### `absurd`
12+
13+
``` purescript
14+
absurd :: forall a. Void -> a
15+
```
16+
17+
#### `coerce`
18+
19+
``` purescript
20+
coerce :: forall f a b. (Contravariant f, Functor f) => f a -> f b
21+
```
22+
23+

docs/Data/Lens/Internal/Wander.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ This module defines the `Wander` type class, which is used to define `Traversal`
66

77
``` purescript
88
class (Strong p, Choice p) <= Wander p where
9-
wander :: forall t a b. (Traversable t) => p a b -> p (t a) (t b)
9+
wander :: forall f s t a b. (forall f. (Applicative f) => (a -> f b) -> s -> f t) -> p a b -> p s t
1010
```
1111

12+
Class for profunctors that support polymorphic traversals.
13+
1214
##### Instances
1315
``` purescript
1416
instance wanderFunction :: Wander Function

docs/Data/Lens/Lens.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ lens :: forall s t a b. (s -> a) -> (s -> b -> t) -> Lens s t a b
1616

1717
Create a `Lens` from a getter/setter pair.
1818

19+
#### `withLens`
20+
21+
``` purescript
22+
withLens :: forall s t a b r. ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
23+
```
24+
25+
#### `cloneLens`
26+
27+
``` purescript
28+
cloneLens :: forall s t a b. ALens s t a b -> Lens s t a b
29+
```
30+
1931

docs/Data/Lens/Traversal.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,38 @@
22

33
This module defines functions for working with traversals.
44

5-
#### `traverse`
5+
#### `traversed`
66

77
``` purescript
8-
traverse :: forall t a b. (Traversable t) => Traversal (t a) (t b) a b
8+
traversed :: forall t a b. (Traversable t) => Traversal (t a) (t b) a b
99
```
1010

1111
Create a `Traversal` which traverses the elements of a `Traversable` functor.
1212

1313
#### `traverseOf`
1414

1515
``` purescript
16-
traverseOf :: forall f s t a b. (Applicative f) => Traversal s t a b -> (a -> f b) -> s -> f t
16+
traverseOf :: forall f s t a b. (Applicative f) => Optic (Star f) s t a b -> (a -> f b) -> s -> f t
1717
```
1818

1919
Turn a pure profunctor `Traversal` into a `lens`-like `Traversal`.
2020

21+
#### `sequenceOf`
22+
23+
``` purescript
24+
sequenceOf :: forall f s t a. (Applicative f) => Optic (Star f) s t (f a) a -> s -> f t
25+
```
26+
27+
Sequence the foci of a `Traversal`, pulling out an `Applicative` effect.
28+
If you do not need the result, see `sequenceOf_` for `Fold`s.
29+
30+
#### `failover`
31+
32+
``` purescript
33+
failover :: forall f s t a b. (Alternative f) => Optic (Star (Tuple (Disj Boolean))) s t a b -> (a -> b) -> s -> f t
34+
```
35+
36+
Tries to map over a `Traversal`; returns `empty`, if the traversal did
37+
not have any new focus.
38+
2139

docs/Data/Lens/Types.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ A lens.
5656
type LensP s a = Lens s s a a
5757
```
5858

59+
#### `ALens`
60+
61+
``` purescript
62+
type ALens s t a b = Optic (Shop a b) s t a b
63+
```
64+
65+
#### `ALensP`
66+
67+
``` purescript
68+
type ALensP s a = ALens s s a a
69+
```
70+
5971
#### `Prism`
6072

6173
``` purescript

0 commit comments

Comments
 (0)