@@ -25,22 +25,19 @@ module Streamly.Prelude
26 , unfoldrM
26 , unfoldrM
30 -- * Elimination
29 -- * Elimination
37− -- * Elimination Special Folds
37+ -- ** Special Folds
@@ -48,6 +45,8 @@ module Streamly.Prelude
52 -- * Filtering
51 -- * Filtering
@@ -66,6 +65,11 @@ module Streamly.Prelude
66 , zipWithM
65 , zipWithM
67 , zipAsyncWith
66 , zipAsyncWith
68 , zipAsyncWithM
67 , zipAsyncWithM
@@ -110,11 +114,11 @@ unfoldrM step = fromStream . go
110-- XXX need eachInterleaved, eachAsync, eachParallel
114-- XXX need eachInterleaved, eachAsync, eachParallel
111-- | Same as @foldWith (<>)@ but more efficient.
115-- | Same as @foldWith (<>)@ but more efficient.
112{-# INLINE each #-}
116{-# INLINE each #-}
113−each :: (Foldable f, Streaming t) => f a -> t m a
117+each :: (Streaming t, Foldable f) => f a -> t m a
114each xs = Prelude.foldr cons nil xs
118each xs = Prelude.foldr cons nil xs
116-- | Read lines from an IO Handle into a stream of Strings.
120-- | Read lines from an IO Handle into a stream of Strings.
117−fromHandle :: (MonadIO m, Streaming t) => IO.Handle -> t m String
121+fromHandle :: (Streaming t, MonadIO m) => IO.Handle -> t m String
118fromHandle h = fromStream $ go
122fromHandle h = fromStream $ go
120 go = Stream $ \_ stp yld -> do
124 go = Stream $ \_ stp yld -> do
@@ -132,7 +136,7 @@ fromHandle h = fromStream $ go
132-- Parallel variants of folds?
136-- Parallel variants of folds?
134-- | Right fold.
138-- | Right fold.
135−foldr :: (Monad m, Streaming t) => (a -> b -> b) -> b -> t m a -> m b
139+foldr :: (Streaming t, Monad m) => (a -> b -> b) -> b -> t m a -> m b
136foldr step acc m = go (toStream m)
140foldr step acc m = go (toStream m)
@@ -154,7 +158,7 @@ foldrM step acc m = go (toStream m)
155-- | Strict left fold. This is typed to work with the foldl package. To use
159-- | Strict left fold. This is typed to work with the foldl package. To use
156-- directly pass 'id' as the third argument.
160-- directly pass 'id' as the third argument.
157−foldl :: (Monad m, Streaming t)
161+foldl :: (Streaming t, Monad m)
158 => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
162 => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
159foldl step begin done m = go begin (toStream m)
163foldl step begin done m = go begin (toStream m)
@@ -166,7 +170,7 @@ foldl step begin done m = go begin (toStream m)
167-- | Strict left fold, with monadic step function. This is typed to work
171-- | Strict left fold, with monadic step function. This is typed to work
168-- with the foldl package. To use directly pass 'id' as the third argument.
172-- with the foldl package. To use directly pass 'id' as the third argument.
169−foldlM :: (Monad m, Streaming t)
173+foldlM :: (Streaming t, Monad m)
170 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
174 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
171foldlM step begin done m = go begin (toStream m)
175foldlM step begin done m = go begin (toStream m)
@@ -202,7 +206,7 @@ toHandle h m = go (toStream m)
203-- | Convert a stream into a list in the underlying monad.
207-- | Convert a stream into a list in the underlying monad.
204{-# INLINABLE toList #-}
208{-# INLINABLE toList #-}
205−toList :: (Monad m, Streaming t) => t m a -> m [a]
209+toList :: (Streaming t, Monad m) => t m a -> m [a]
206toList = foldrM (\a xs -> liftM (a :) xs) (return [])
210toList = foldrM (\a xs -> liftM (a :) xs) (return [])
208-- | Take first 'n' elements from the stream and discard the rest.
212-- | Take first 'n' elements from the stream and discard the rest.