@@ -143,7 +143,13 @@ instance applicativeStateL :: Applicative (StateL s) where
143143 pure a = StateL \s -> { accum: s, value: a }
144144
145145-- | Fold a data structure from the left, keeping all intermediate results
146- -- | instead of only the final result.
146+ -- | instead of only the final result. Note that the initial value does not
147+ -- | appear in the result (unlike Haskell's `Prelude.scanl`).
148+ -- |
149+ -- | ```purescript
150+ -- | scanl (+) 0 [1,2,3] = [1,3,6]
151+ -- | scanl (-) 10 [1,2,3] = [9,7,4]
152+ -- | ```
147153scanl :: forall a b f . (Traversable f ) => (b -> a -> b ) -> b -> f a -> f b
148154scanl f b0 xs = (mapAccumL (\b a -> let b' = f b a in { accum: b', value: b' }) b0 xs).value
149155
@@ -173,7 +179,13 @@ instance applicativeStateR :: Applicative (StateR s) where
173179 pure a = StateR \s -> { accum: s, value: a }
174180
175181-- | Fold a data structure from the right, keeping all intermediate results
176- -- | instead of only the final result.
182+ -- | instead of only the final result. Note that the initial value does not
183+ -- | appear in the result (unlike Haskell's `Prelude.scanr`).
184+ -- |
185+ -- | ```purescript
186+ -- | scanr (+) 0 [1,2,3] = [1,3,6]
187+ -- | scanr (flip (-)) 10 [1,2,3] = [4,5,7]
188+ -- | ```
177189scanr :: forall a b f . (Traversable f ) => (a -> b -> b ) -> b -> f a -> f b
178190scanr f b0 xs = (mapAccumR (\b a -> let b' = f a b in { accum: b', value: b' }) b0 xs).value
179191
0 commit comments