File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 107107
108108 mapAccumR :: forall a b s f. (Traversable f) => (s -> a -> Tuple s b) -> s -> f a -> Tuple s (f b)
109109
110+ scanl :: forall a b f. (Traversable f) => (b -> a -> b) -> b -> f a -> f b
111+
112+ scanr :: forall a b f. (Traversable f) => (a -> b -> b) -> b -> f a -> f b
113+
110114 zipWithA :: forall m a b c. (Applicative m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ module Data.Traversable
44 , sequence
55 , for
66 , zipWithA
7+ , scanl
8+ , scanr
79 , mapAccumL
810 , mapAccumR
911 ) where
@@ -74,6 +76,9 @@ instance applyStateL :: Apply (StateL s) where
7476instance applicativeStateL :: Applicative (StateL s ) where
7577 pure a = StateL $ \s -> Tuple s a
7678
79+ scanl :: forall a b f . (Traversable f ) => (b -> a -> b ) -> b -> f a -> f b
80+ scanl f b0 xs = snd $ mapAccumL (\b a -> let b' = f b a in Tuple b' b') b0 xs
81+
7782mapAccumL :: forall a b s f . (Traversable f ) => (s -> a -> Tuple s b ) -> s -> f a -> Tuple s (f b )
7883mapAccumL f s0 xs = stateL (traverse (\a -> StateL $ \s -> f s a) xs) s0
7984
@@ -94,6 +99,9 @@ instance applyStateR :: Apply (StateR s) where
9499instance applicativeStateR :: Applicative (StateR s ) where
95100 pure a = StateR $ \s -> Tuple s a
96101
102+ scanr :: forall a b f . (Traversable f ) => (a -> b -> b ) -> b -> f a -> f b
103+ scanr f b0 xs = snd $ mapAccumR (\b a -> let b' = f a b in Tuple b' b') b0 xs
104+
97105mapAccumR :: forall a b s f . (Traversable f ) => (s -> a -> Tuple s b ) -> s -> f a -> Tuple s (f b )
98106mapAccumR f s0 xs = stateR (traverse (\a -> StateR $ \s -> f s a) xs) s0
99107
You can’t perform that action at this time.
0 commit comments