0 | module Control.Lens.Each
 1 |
 2 | import Control.Monad.Identity
 3 | import Control.Applicative.Const
 4 | import Control.Lens.Optic
 5 | import Control.Lens.Iso
 6 | import Control.Lens.Lens
 7 | import Control.Lens.Optional
 8 | import Control.Lens.Traversal
 9 | import Control.Lens.Indexed
10 |
11 | %default total
12 |
13 |
14 | ||| An interface for accessing every element of a container.
15 | |||
16 | ||| This can be thought of as a generalized version of `traversed` for
17 | ||| containers that do not have a `Traversable` implementation.
18 | public export
19 | interface Each s t a b | s where
20 |
21 |   ||| Access every element of a container at the same time.
22 |   |||
23 |   ||| This can be thought of as a generalized version of `traversed` for
24 |   ||| containers that do not have a `Traversable` implementation.
25 |   each : Traversal s t a b
26 |
27 | ||| An interface for accessing every element of a container, providing an index.
28 | |||
29 | ||| This can be thought of as a generalized version of `itraversed` for
30 | ||| containers that do not have a `Traversable` implementation.
31 | public export
32 | interface Each s t a b => IEach i s t a b | s where
33 |
34 |   ||| Access every element of a container at the same time, providing an index.
35 |   |||
36 |   ||| This can be thought of as a generalized version of `itraversed` for
37 |   ||| containers that do not have a `Traversable` implementation.
38 |   ieach : IndexedTraversal i s t a b
39 |
40 |
41 | public export
42 | [Traversed] Traversable f => Each (f a) (f b) a b where
43 |   each = traversed
44 |
45 | public export
46 | [Ordinal] Num i => Each s t a b => IEach i s t a b where
47 |   ieach = iordinal each
48 |
49 |
50 | public export
51 | Each (Identity a) (Identity b) a b where
52 |   each = Id_
53 |
54 | public export
55 | Each (Const a b) (Const c d) a c where
56 |   each = Const_
57 |