11module Test.Main where
22
33import Prelude
4-
5- import Data.Lens (view , traversed , _1 , _2 , _Just , _Left , lens )
6- import Data.Lens.Index (ix )
7- import Data.Lens.Setter (iover )
8- import Data.Lens.Lens (ilens , IndexedLens , cloneIndexedLens )
9- import Data.Lens.Fold ((^?))
10- import Data.Lens.Fold.Partial ((^?!), (^@?!))
11- import Data.Lens.Zoom (Traversal , Traversal' , Lens , Lens' , zoom )
12- import Data.Tuple (Tuple (..))
13- import Data.Maybe (Maybe (..))
14- import Data.Either (Either (..))
154import Control.Monad.Eff (Eff )
165import Control.Monad.Eff.Console (CONSOLE , logShow )
176import Control.Monad.State (evalState , get )
7+ import Data.Distributive (class Distributive )
8+ import Data.Either (Either (..))
9+ import Data.Lens (_1 , _2 , _Just , _Left , collectOf , lens , traversed , view )
10+ import Data.Lens.Fold ((^?))
11+ import Data.Lens.Fold.Partial ((^?!), (^@?!))
12+ import Data.Lens.Grate (cloneGrate , grate , zipWithOf )
13+ import Data.Lens.Index (ix )
14+ import Data.Lens.Lens (ilens , IndexedLens , cloneIndexedLens )
15+ import Data.Lens.Setter (iover )
16+ import Data.Lens.Types (Grate )
17+ import Data.Lens.Zoom (Traversal , Traversal' , Lens , Lens' , zoom )
18+ import Data.Maybe (Maybe (..))
19+ import Data.Tuple (Tuple (..), fst , snd )
1820import Partial.Unsafe (unsafePartial )
1921
2022-- Traversing an array nested within a record
@@ -60,6 +62,16 @@ cloneTest = iover (cloneIndexedLens i_2) Tuple (Tuple 1 2)
6062i_2 :: forall a b c . IndexedLens Int (Tuple a b ) (Tuple a c ) b c
6163i_2 = ilens (\(Tuple _ b) -> Tuple 0 b) (\(Tuple a _) b -> Tuple a b)
6264
65+ -- Grates
66+ aGrateExample :: forall a b . Grate (Tuple a a ) (Tuple b b ) a b
67+ aGrateExample = grate \f -> Tuple (f fst) (f snd)
68+
69+ collectOfTest :: forall f a b . Distributive f => (a -> f b ) -> Tuple a a -> f (Tuple b b )
70+ collectOfTest = collectOf aGrateExample
71+
72+ summing :: Tuple Int Int -> Tuple Int Int -> Tuple Int Int
73+ summing = zipWithOf (cloneGrate aGrateExample) (+)
74+
6375main :: forall e . Eff (console :: CONSOLE | e ) Unit
6476main = do
6577 logShow $ view bars doc
@@ -68,3 +80,4 @@ main = do
6880 logShow $ unsafePartial $ Tuple 0 1 ^@?! i_2
6981 logShow stateTest
7082 logShow cloneTest
83+ logShow (summing (Tuple 1 2 ) (Tuple 3 4 ))
0 commit comments