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

Commit b0d165b

Browse files
committed
Added another example for Each.
1 parent 376d19f commit b0d165b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

examples/Each.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Example.Control.Lens.Each where
22

33
import Control.Lens
4+
-- Have to import typeclass because re-exporting doesn't work yet.
5+
import Control.Lens.Each (Each)
46

57
import Data.String
68
import Data.Tuple
@@ -13,6 +15,19 @@ module Example.Control.Lens.Each where
1315
bar :: Tuple Number Number
1416
bar = ("Hi" ~ "everybody!") # each %~ length
1517

18+
data RGBA = RGBA Number Number Number Number
19+
20+
instance eachRGBA :: Each RGBA RGBA Number Number where
21+
each f (RGBA r g b a) = RGBA <$> f r <*> f g <*> f b <*> f a
22+
23+
instance showRGBA :: Show RGBA where
24+
show (RGBA r g b a) = "RGBA (" ++ show r ++ ") (" ++ show g ++ ") (" ++ show b ++ ") (" ++ show a ++ ")"
25+
26+
baz :: RGBA
27+
baz = RGBA 0 128 255 1
28+
1629
main = do
1730
print foo
1831
print bar
32+
-- Another case of broken inference...
33+
print ((baz # each +~ 10) :: RGBA)

0 commit comments

Comments
 (0)