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 103103
104104 mapAccumR :: forall a b s f. (Traversable f) => (s -> a -> Tuple s b) -> s -> f a -> Tuple s (f b)
105105
106+ scanl :: forall a b f. (Traversable f) => (b -> a -> b) -> b -> f a -> f b
107+
108+ scanr :: forall a b f. (Traversable f) => (a -> b -> b) -> b -> f a -> f b
109+
106110 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
@@ -67,6 +69,9 @@ instance applyStateL :: Apply (StateL s) where
6769instance applicativeStateL :: Applicative (StateL s ) where
6870 pure a = StateL $ \s -> Tuple s a
6971
72+ scanl :: forall a b f . (Traversable f ) => (b -> a -> b ) -> b -> f a -> f b
73+ scanl f b0 xs = snd $ mapAccumL (\b a -> let b' = f b a in Tuple b' b') b0 xs
74+
7075mapAccumL :: forall a b s f . (Traversable f ) => (s -> a -> Tuple s b ) -> s -> f a -> Tuple s (f b )
7176mapAccumL f s0 xs = stateL (traverse (\a -> StateL $ \s -> f s a) xs) s0
7277
@@ -87,6 +92,9 @@ instance applyStateR :: Apply (StateR s) where
8792instance applicativeStateR :: Applicative (StateR s ) where
8893 pure a = StateR $ \s -> Tuple s a
8994
95+ scanr :: forall a b f . (Traversable f ) => (a -> b -> b ) -> b -> f a -> f b
96+ scanr f b0 xs = snd $ mapAccumR (\b a -> let b' = f a b in Tuple b' b') b0 xs
97+
9098mapAccumR :: forall a b s f . (Traversable f ) => (s -> a -> Tuple s b ) -> s -> f a -> Tuple s (f b )
9199mapAccumR f s0 xs = stateR (traverse (\a -> StateR $ \s -> f s a) xs) s0
92100
You can’t perform that action at this time.
0 commit comments