on master help sign in
update/rearrange documentation
89eec18Harendra Kumar
src/Streamly/Prelude.hs+48−22
@@ -91,31 +91,32 @@ module Streamly.Prelude
91 , foldxM
91 , foldxM
92
92
93 -- ** Specialized Folds
93 -- ** Specialized Folds
94− , null
94+
95+ -- Filtering folds: extract parts of the stream
95 , head
96 , head
96 , tail
97 , tail
97 , last
98 , last
98 , init
99 , init
100+
101+ -- Conditional folds: may terminate early based on a condition
102+ , null
99 , elem
103 , elem
104+ , elemIndex
100 , notElem
105 , notElem
101− , length
106+ , lookup
107+ , find
108+ , findIndex
102 , all
109 , all
103 , any
110 , any
104 , and
111 , and
105 , or
112 , or
113+
114+ -- Full folds - need to go through all elements
115+ , length
106 , maximum
116 , maximum
107 , minimum
117 , minimum
108 , sum
118 , sum
109 , product
119 , product
110− , lookup
111− , find
112−
113− -- *** Indices
114− , findIndices
115− , findIndex
116− , elemIndices
117− , elemIndex
118−
119
120
120 -- ** Map and Fold
121 -- ** Map and Fold
121 , mapM_
122 , mapM_
@@ -126,7 +127,14 @@ module Streamly.Prelude
126 , toHandle
127 , toHandle
127
128
128 -- * Transformation
129 -- * Transformation
129− -- ** By folding (scans)
130+ -- ** Mapping
131+ , Serial.map
132+ , mapM
133+ , sequence
134+
135+ -- ** Scanning
136+ -- | Scan is a transformation by continuously folding the result with the
137+ -- next element of the stream.
130 , scanl'
138 , scanl'
131 , scanlM'
139 , scanlM'
132 , scanx
140 , scanx
@@ -141,20 +149,19 @@ module Streamly.Prelude
141 , dropWhile
149 , dropWhile
142 , dropWhileM
150 , dropWhileM
143
151
144− -- ** Mapping
152+ -- ** Inserting
145− , Serial.map
153+ , intersperseM
146− , mapM
147− , sequence
148−
149− -- ** Map and Filter
150− , mapMaybe
151− , mapMaybeM
152
154
153 -- ** Reordering
155 -- ** Reordering
154 , reverse
156 , reverse
155
157
156− -- ** Inserting
158+ -- ** Indices
157− , intersperseM
159+ , findIndices
160+ , elemIndices
161+
162+ -- ** Map and Filter
163+ , mapMaybe
164+ , mapMaybeM
158
165
159 -- * Zipping
166 -- * Zipping
160 , zipWith
167 , zipWith
@@ -303,10 +310,29 @@ unfoldrMSerial step seed = fromStreamS (S.unfoldrM step seed)
303-- Specialized Generation
310-- Specialized Generation
304------------------------------------------------------------------------------
311------------------------------------------------------------------------------
305
312
313+-- Faster than yieldM because there is no bind. Usually we can construct a
314+-- stream from a pure value using "pure" in an applicative, however in case of
315+-- Zip streams pure creates an infinite stream.
316+--
317+-- | Create a singleton stream from a pure value. In monadic streams, 'pure' or
318+-- 'return' can be used in place of 'yield', however, in Zip applicative
319+-- streams 'pure' is equivalent to 'repeat'.
320+--
321+-- @since 0.4.0
306{-# INLINE yield #-}
322{-# INLINE yield #-}
307yield :: IsStream t => a -> t m a
323yield :: IsStream t => a -> t m a
308yield a = K.yield a
324yield a = K.yield a
309
325
326+-- | Create a singleton stream from a monadic action. Same as @m \`consM` nil@
327+-- but more efficient.
328+--
329+-- @
330+-- > toList $ yieldM getLine
331+-- hello
332+-- ["hello"]
333+-- @
334+--
335+-- @since 0.4.0
310{-# INLINE yieldM #-}
336{-# INLINE yieldM #-}
311yieldM :: (Monad m, IsStream t) => m a -> t m a
337yieldM :: (Monad m, IsStream t) => m a -> t m a
312yieldM m = K.yieldM m
338yieldM m = K.yieldM m
src/Streamly/Streams/StreamK.hs−19
@@ -396,28 +396,9 @@ unfoldrM step = go
396-- Special generation
396-- Special generation
397-------------------------------------------------------------------------------
397-------------------------------------------------------------------------------
398
398
399−-- Faster than yieldM because there is no bind. Usually we can construct a
400−-- stream from a pure value using "pure" in an applicative, however in case of
401−-- Zip streams pure creates an infinite stream.
402−--
403−-- | Create a singleton stream from a pure value. In monadic streams, 'pure' or
404−-- 'return' can be used in place of 'yield', however, in Zip applicative
405−-- streams 'pure' is equivalent to 'repeat'.
406−--
407−-- @since 0.4.0
408yield :: IsStream t => a -> t m a
399yield :: IsStream t => a -> t m a
409yield a = fromStream $ Stream $ \_ _ single _ -> single a
400yield a = fromStream $ Stream $ \_ _ single _ -> single a
410
401
411−-- | Create a singleton stream from a monadic action. Same as @m \`consM` nil@
412−-- but more efficient.
413−--
414−-- @
415−-- > toList $ yieldM getLine
416−-- hello
417−-- ["hello"]
418−-- @
419−--
420−-- @since 0.4.0
421{-# INLINE yieldM #-}
402{-# INLINE yieldM #-}
422yieldM :: (Monad m, IsStream t) => m a -> t m a
403yieldM :: (Monad m, IsStream t) => m a -> t m a
423yieldM m = fromStream $ Stream $ \_ _ single _ -> m >>= single
404yieldM m = fromStream $ Stream $ \_ _ single _ -> m >>= single