Skip to content

Commit d7f198c

Browse files
committed
Merge pull request #21 from zrho/master
Indexed optics.
2 parents a6e0d50 + e6f4e59 commit d7f198c

File tree

21 files changed

+593
-8
lines changed

21 files changed

+593
-8
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"purescript-profunctor": "~0.3.0",
2424
"purescript-sets": "~0.5.1",
2525
"purescript-unsafe-coerce": "~0.1.0",
26-
"purescript-transformers": "~0.8.1"
26+
"purescript-transformers": "~0.8.1",
27+
"purescript-functor-compose": "~0.0.1"
2728
}
2829
}

docs/Data/Lens/Fold.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,60 @@ replicated :: forall a b t f. (Applicative f, Contravariant f) => Int -> Optic (
223223

224224
Replicates the elements of a fold.
225225

226+
#### `ifoldMapOf`
227+
228+
``` purescript
229+
ifoldMapOf :: forall r i s t a b. IndexedFold r i s t a b -> (i -> a -> r) -> s -> r
230+
```
231+
232+
Fold map over an `IndexedFold`.
233+
234+
#### `ifoldrOf`
235+
236+
``` purescript
237+
ifoldrOf :: forall i s t a b r. IndexedFold (Endo r) i s t a b -> (i -> a -> r -> r) -> r -> s -> r
238+
```
239+
240+
Right fold over an `IndexedFold`.
241+
242+
#### `ifoldlOf`
243+
244+
``` purescript
245+
ifoldlOf :: forall i s t a b r. IndexedFold (Dual (Endo r)) i s t a b -> (i -> r -> a -> r) -> r -> s -> r
246+
```
247+
248+
Left fold over an `IndexedFold`.
249+
250+
#### `iallOf`
251+
252+
``` purescript
253+
iallOf :: forall i s t a b r. (BooleanAlgebra r) => IndexedFold (Conj r) i s t a b -> (i -> a -> r) -> s -> r
254+
```
255+
256+
Whether all foci of an `IndexedFold` satisfy a predicate.
257+
258+
#### `ianyOf`
259+
260+
``` purescript
261+
ianyOf :: forall i s t a b r. (BooleanAlgebra r) => IndexedFold (Disj r) i s t a b -> (i -> a -> r) -> s -> r
262+
```
263+
264+
Whether any focus of an `IndexedFold` satisfies a predicate.
265+
266+
#### `itoListOf`
267+
268+
``` purescript
269+
itoListOf :: forall i s t a b. IndexedFold (Endo (List (Tuple i a))) i s t a b -> s -> List (Tuple i a)
270+
```
271+
272+
Collects the foci of an `IndexedFold` into a list.
273+
274+
#### `itraverseOf_`
275+
276+
``` purescript
277+
itraverseOf_ :: forall i f s t a b r. (Applicative f) => IndexedFold (Endo (f Unit)) i s t a b -> (i -> a -> f r) -> s -> f Unit
278+
```
279+
280+
Traverse the foci of an `IndexedFold`, discarding the results.
281+
226282

docs/Data/Lens/Getter.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ view :: forall s t a b. Getter s t a b -> s -> a
1010

1111
View the focus of a `Getter`.
1212

13+
#### `iview`
14+
15+
``` purescript
16+
iview :: forall i s t a b. IndexedFold (Tuple i a) i s t a b -> s -> Tuple i a
17+
```
18+
19+
View the focus of a `Getter` and its index.
20+
1321
#### `(^.)`
1422

1523
``` purescript
@@ -28,4 +36,20 @@ to :: forall s a f. (Contravariant f) => (s -> a) -> Optic (Star f) s s a a
2836

2937
Convert a function into a getter.
3038

39+
#### `use`
40+
41+
``` purescript
42+
use :: forall s t a b m. (MonadState s m) => Getter s t a b -> m a
43+
```
44+
45+
View the focus of a `Getter` in the state of a monad.
46+
47+
#### `iuse`
48+
49+
``` purescript
50+
iuse :: forall i s t a b m. (MonadState s m) => IndexedFold (Tuple i a) i s t a b -> m (Tuple i a)
51+
```
52+
53+
View the focus of a `Getter` and its index in the state of a monad.
54+
3155

docs/Data/Lens/Indexed.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Module Data.Lens.Indexed
2+
3+
#### `unIndex`
4+
5+
``` purescript
6+
unIndex :: forall p i s t a b. (Profunctor p) => IndexedOptic p i s t a b -> Optic p s t a b
7+
```
8+
9+
Converts an `IndexedOptic` to an `Optic` by forgetting indices.
10+
11+
#### `iwander`
12+
13+
``` purescript
14+
iwander :: forall p i s t a b. (Wander p) => (forall f. (Applicative f) => (i -> a -> f b) -> s -> f t) -> Indexed p i a b -> p s t
15+
```
16+
17+
Converts a `lens`-like indexed traversal to an `IndexedTraversal`.
18+
19+
#### `positions`
20+
21+
``` purescript
22+
positions :: forall p s t a b. (Wander p) => Traversal s t a b -> IndexedOptic p Int s t a b
23+
```
24+
25+
Converts a `Traversal` to an `IndexedTraversal` by using the integer positions as indices.
26+
27+

docs/Data/Lens/Internal/Focusing.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Module Data.Lens.Internal.Focusing
2+
3+
This module defines the `Focusing` functor
4+
5+
#### `Focusing`
6+
7+
``` purescript
8+
newtype Focusing m s a
9+
= Focusing (m (Tuple s a))
10+
```
11+
12+
The functor used to zoom into `StateT`.
13+
14+
##### Instances
15+
``` purescript
16+
instance focusingFunctor :: (Functor m) => Functor (Focusing m s)
17+
instance focusingApply :: (Apply m, Semigroup s) => Apply (Focusing m s)
18+
instance focusingApplicative :: (Applicative m, Monoid s) => Applicative (Focusing m s)
19+
```
20+
21+
#### `runFocusing`
22+
23+
``` purescript
24+
runFocusing :: forall m s a. Focusing m s a -> m (Tuple s a)
25+
```
26+
27+

docs/Data/Lens/Internal/Forget.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Module Data.Lens.Internal.Forget
2+
3+
#### `Forget`
4+
5+
``` purescript
6+
newtype Forget r a b
7+
= Forget (a -> r)
8+
```
9+
10+
Profunctor that forgets the `b` value and returns (and accumulates) a
11+
value of type `r`.
12+
13+
`Forget r` is isomorphic to `Star (Const r)`, but can be given a `Cochoice`
14+
instance.
15+
16+
##### Instances
17+
``` purescript
18+
instance profunctorForget :: Profunctor (Forget r)
19+
instance choiceForget :: (Monoid r) => Choice (Forget r)
20+
instance strongForget :: Strong (Forget r)
21+
instance cochoiceForget :: Cochoice (Forget r)
22+
instance wanderForget :: (Monoid r) => Wander (Forget r)
23+
```
24+
25+
#### `runForget`
26+
27+
``` purescript
28+
runForget :: forall r a b. Forget r a b -> a -> r
29+
```
30+
31+
Unwrap a value of type `Forget`.
32+
33+

docs/Data/Lens/Internal/Indexed.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Module Data.Lens.Internal.Indexed
2+
3+
This module defines the `Indexed` profunctor.
4+
5+
#### `Indexed`
6+
7+
``` purescript
8+
newtype Indexed p i s t
9+
= Indexed (p (Tuple i s) t)
10+
```
11+
12+
Profunctor used for `IndexedOptic`s.
13+
14+
##### Instances
15+
``` purescript
16+
instance indexedProfunctor :: (Profunctor p) => Profunctor (Indexed p i)
17+
instance indexedStrong :: (Strong p) => Strong (Indexed p i)
18+
instance indexedChoice :: (Choice p) => Choice (Indexed p i)
19+
```
20+
21+
#### `fromIndexed`
22+
23+
``` purescript
24+
fromIndexed :: forall p i s t. Indexed p i s t -> p (Tuple i s) t
25+
```
26+
27+
Unwrap a value of type `Indexed`.
28+
29+

docs/Data/Lens/Internal/Re.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Module Data.Lens.Internal.Re
2+
3+
This module defines the `Re` profunctor
4+
5+
#### `Re`
6+
7+
``` purescript
8+
newtype Re p s t a b
9+
= Re (p b a -> p t s)
10+
```
11+
12+
##### Instances
13+
``` purescript
14+
instance profunctorRe :: (Profunctor p) => Profunctor (Re p s t)
15+
instance choiceRe :: (Choice p) => Cochoice (Re p s t)
16+
instance cochoiceRe :: (Cochoice p) => Choice (Re p s t)
17+
instance strongRe :: (Strong p) => Costrong (Re p s t)
18+
instance costrongRe :: (Costrong p) => Strong (Re p s t)
19+
```
20+
21+
#### `runRe`
22+
23+
``` purescript
24+
runRe :: forall p s t a b. Re p s t a b -> p b a -> p t s
25+
```
26+
27+

docs/Data/Lens/Internal/Tagged.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ newtype Tagged a b
1313
``` purescript
1414
instance taggedProfunctor :: Profunctor Tagged
1515
instance taggedChoice :: Choice Tagged
16+
instance taggedCostrong :: Costrong Tagged
1617
```
1718

1819
#### `unTagged`

docs/Data/Lens/Iso.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ cloneIso :: forall s t a b. AnIso s t a b -> Iso s t a b
2626

2727
Extracts an `Iso` from `AnIso`.
2828

29+
#### `re`
30+
31+
``` purescript
32+
re :: forall p s t a b. Optic (Re p a b) s t a b -> Optic p b a t s
33+
```
34+
35+
Reverses an optic.
36+
2937
#### `au`
3038

3139
``` purescript

0 commit comments

Comments
 (0)