on master help sign in
minor changes for haddock docs
commita1f654dbbd530bf7829619167aec1f1a0b5070d9 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 12 Feb 2018, 07:23 (9 years ago) parent42df609
1 file changed+15−11
src/Streamly/Prelude.hs+15−11
src/Streamly/Prelude.hs+15−11
@@ -25,22 +25,19 @@ module Streamly.Prelude
2525 , unfoldr
2626 , unfoldrM
2727 , each
28− , fromHandle
2928
3029 -- * Elimination
30+ -- ** General Folds
3131 , foldr
3232 , foldrM
3333 , foldl
3434 , foldlM
3535 , uncons
3636
37− -- * Elimination Special Folds
37+ -- ** Special Folds
3838 , toList
39− , toHandle
4039 , all
4140 , any
42− , sum
43− , product
4441 , head
4542 , last
4643 , length
@@ -48,6 +45,8 @@ module Streamly.Prelude
4845 , notElem
4946 , maximum
5047 , minimum
48+ , sum
49+ , product
5150
5251 -- * Filtering
5352 , filter
@@ -66,6 +65,11 @@ module Streamly.Prelude
6665 , zipWithM
6766 , zipAsyncWith
6867 , zipAsyncWithM
68+
69+ -- * IO
70+ , fromHandle
71+ , toHandle
72+
6973 )
7074where
7175
@@ -110,11 +114,11 @@ unfoldrM step = fromStream . go
110114-- XXX need eachInterleaved, eachAsync, eachParallel
111115-- | Same as @foldWith (<>)@ but more efficient.
112116{-# INLINE each #-}
113−each :: (Foldable f, Streaming t) => f a -> t m a
117+each :: (Streaming t, Foldable f) => f a -> t m a
114118each xs = Prelude.foldr cons nil xs
115119
116120-- | 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
118122fromHandle h = fromStream $ go
119123 where
120124 go = Stream $ \_ stp yld -> do
@@ -132,7 +136,7 @@ fromHandle h = fromStream $ go
132136-- Parallel variants of folds?
133137
134138-- | 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
136140foldr step acc m = go (toStream m)
137141 where
138142 go m1 =
@@ -154,7 +158,7 @@ foldrM step acc m = go (toStream m)
154158
155159-- | Strict left fold. This is typed to work with the foldl package. To use
156160-- directly pass 'id' as the third argument.
157−foldl :: (Monad m, Streaming t)
161+foldl :: (Streaming t, Monad m)
158162 => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
159163foldl step begin done m = go begin (toStream m)
160164 where
@@ -166,7 +170,7 @@ foldl step begin done m = go begin (toStream m)
166170
167171-- | Strict left fold, with monadic step function. This is typed to work
168172-- 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)
170174 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
171175foldlM step begin done m = go begin (toStream m)
172176 where
@@ -202,7 +206,7 @@ toHandle h m = go (toStream m)
202206
203207-- | Convert a stream into a list in the underlying monad.
204208{-# INLINABLE toList #-}
205−toList :: (Monad m, Streaming t) => t m a -> m [a]
209+toList :: (Streaming t, Monad m) => t m a -> m [a]
206210toList = foldrM (\a xs -> liftM (a :) xs) (return [])
207211
208212-- | Take first 'n' elements from the stream and discard the rest.