on master help sign in
Merge branch 'Abhiroop-foldrm-diff'
commit3838eb4022667df3d6b2344741b1889fcf101a25 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 26 Mar 2018, 04:49 (9 years ago) parentf8ec8351d3fb25
2 files changed+10−4
Changelog.md+6 src/Streamly/Prelude.hs+4−4
Changelog.md+6
@@ -1,3 +1,9 @@
1+## Unrelased
2+
3+### Breaking change
4+* Change the type of `foldrM` to take a pure seed and pure second argument in the step function
5+
6+
17## 0.1.2
28
39### Enhancements
src/Streamly/Prelude.hs+4−4
@@ -167,13 +167,13 @@ foldr step acc m = go (toStream m)
167167
168168-- | Right fold with a monadic step function. See 'toList' for an example use.
169169{-# INLINE foldrM #-}
170−foldrM :: Streaming t => (a -> m b -> m b) -> m b -> t m a -> m b
170+foldrM :: (Streaming t, Monad m) => (a -> b -> m b) -> b -> t m a -> m b
171171foldrM step acc m = go (toStream m)
172172 where
173173 go m1 =
174− let stop = acc
174+ let stop = return acc
175175 yield a Nothing = step a acc
176− yield a (Just x) = step a (go x)
176+ yield a (Just x) = (go x) >>= (step a)
177177 in (runStream m1) Nothing stop yield
178178
179179-- | Scan left. A strict left fold which accumulates the result of its reduction steps inside a stream, from left.
@@ -255,7 +255,7 @@ toHandle h m = go (toStream m)
255255-- | Convert a stream into a list in the underlying monad.
256256{-# INLINABLE toList #-}
257257toList :: (Streaming t, Monad m) => t m a -> m [a]
258−toList = foldrM (\a xs -> fmap (a :) xs) (return [])
258+toList = foldrM (\a xs -> return (a : xs)) []
259259
260260-- | Take first 'n' elements from the stream and discard the rest.
261261{-# INLINE take #-}