Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 0110b08

Browse files
committed
Added Each.
1 parent e3c2c93 commit 0110b08

5 files changed

Lines changed: 54 additions & 1 deletion

File tree

examples/Each.purs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Example.Control.Lens.Each where
2+
3+
import Control.Lens
4+
5+
import Data.String
6+
import Data.Tuple
7+
8+
import Debug.Trace
9+
10+
foo :: [Number]
11+
foo = [1,2,3] # each +~ 2
12+
13+
bar :: Tuple Number Number
14+
bar = ("Hi" ~ "everybody!") # each %~ length
15+
16+
main = do
17+
print foo
18+
print bar

gulpfile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var paths =
2323

2424
var options =
2525
{ test: { main: 'Test.Control.Lens'
26-
, verboseErrors: true
2726
}
2827
};
2928

src/Control/Lens.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Control.Lens
1818
, tail
1919
, uncons
2020
, unsnoc
21+
-- Each
22+
, each
2123
-- Equality
2224
, simple
2325
, simply
@@ -163,6 +165,7 @@ module Control.Lens
163165

164166
import qualified Control.Lens.At as At
165167
import qualified Control.Lens.Cons as Cons
168+
import qualified Control.Lens.Each as Each
166169
import qualified Control.Lens.Equality as Equality
167170
import qualified Control.Lens.Fold as Fold
168171
import qualified Control.Lens.Getter as Getter
@@ -199,6 +202,9 @@ module Control.Lens
199202
uncons = Cons.uncons
200203
unsnoc = Cons.unsnoc
201204

205+
-- Each
206+
each = Each.each
207+
202208
-- Equality
203209
simple = Equality.simple
204210
simply = Equality.simply

src/Control/Lens/Each.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Control.Lens.Each where
2+
3+
import Control.Lens.Type (Traversal())
4+
5+
import Data.Traversable (traverse)
6+
import Data.Tuple (Tuple(..))
7+
8+
class Each s t a b where
9+
each :: Traversal s t a b
10+
11+
instance eachTuple :: Each (Tuple a a) (Tuple b b) a b where
12+
each f (Tuple a b) = Tuple <$> f a <*> f b
13+
14+
instance eachArray :: Each [a] [b] a b where
15+
each = traverse

src/Control/Lens/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@
9494
unsnoc :: forall a s. (Snoc s s a a) => s a -> Maybe (Tuple (s a) a)
9595

9696

97+
## Module Control.Lens.Each
98+
99+
### Type Classes
100+
101+
class Each s t a b where
102+
each :: Traversal s t a b
103+
104+
105+
### Type Class Instances
106+
107+
instance eachArray :: Each [a] [b] a b
108+
109+
instance eachTuple :: Each (Tuple a a) (Tuple b b) a b
110+
111+
97112
## Module Control.Lens.Equality
98113

99114
### Values

0 commit comments

Comments
 (0)