@@ -145,6 +145,8 @@ import Streamly.Streams
145145------------------------------------------------------------------------------
146146
147147-- | Build a Stream by unfolding pure steps starting from a seed.
148+--
149+-- @since 0.1.0
148150unfoldr :: IsStream t => (b -> Maybe (a, b)) -> b -> t m a
149151unfoldr step = fromStream . go
150152 where
@@ -154,6 +156,8 @@ unfoldr step = fromStream . go
154156 Just (a, b) -> yld a (go b)
155157
156158-- | Build a Stream by unfolding monadic steps starting from a seed.
159+--
160+-- @since 0.1.0
157161unfoldrM :: (IsStream t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a
158162unfoldrM step = fromStream . go
159163 where
@@ -164,11 +168,15 @@ unfoldrM step = fromStream . go
164168 Just (a, b) -> yld a (go b)
165169
166170-- | Construct a stream from a 'Foldable' container.
171+--
172+-- @since 0.2.0
167173{-# INLINE fromFoldable #-}
168174fromFoldable :: (IsStream t, Foldable f) => f a -> t m a
169175fromFoldable = Prelude.foldr cons nil
170176
171177-- | Same as 'fromFoldable'.
178+--
179+-- @since 0.1.0
172180{-# DEPRECATED each "Please use fromFoldable instead." #-}
173181{-# INLINE each #-}
174182each :: (IsStream t, Foldable f) => f a -> t m a
@@ -182,10 +190,14 @@ each = fromFoldable
182190-- hello
183191-- ["hello"]
184192-- @
193+--
194+-- @since 0.2.0
185195once :: (IsStream t, Monad m) => m a -> t m a
186196once = fromStream . S.once
187197
188198-- | Generate a stream by performing a monadic action @n@ times.
199+--
200+-- @since 0.1.1
189201replicateM :: (IsStream t, Monad m) => Int -> m a -> t m a
190202replicateM n m = fromStream $ go n
191203 where
@@ -195,6 +207,8 @@ replicateM n m = fromStream $ go n
195207 else m >>= \a -> yld a (go (cnt - 1))
196208
197209-- | Generate a stream by repeatedly executing a monadic action forever.
210+--
211+-- @since 0.2.0
198212repeatM :: (IsStream t, Monad m) => m a -> t m a
199213repeatM = fromStream . go
200214 where
@@ -202,6 +216,8 @@ repeatM = fromStream . go
202216 m >>= \a -> yld a (go m)
203217
204218-- | Iterate a pure function from a seed value, streaming the results forever.
219+--
220+-- @since 0.1.2
205221iterate :: IsStream t => (a -> a) -> a -> t m a
206222iterate step = fromStream . go
207223 where
@@ -209,6 +225,8 @@ iterate step = fromStream . go
209225
210226-- | Iterate a monadic function from a seed value, streaming the results
211227-- forever.
228+--
229+-- @since 0.1.2
212230iterateM :: (IsStream t, Monad m) => (a -> m a) -> a -> t m a
213231iterateM step = fromStream . go
214232 where
@@ -217,6 +235,8 @@ iterateM step = fromStream . go
217235 yld s (go a)
218236
219237-- | Read lines from an IO Handle into a stream of Strings.
238+--
239+-- @since 0.1.0
220240fromHandle :: (IsStream t, MonadIO m) => IO.Handle -> t m String
221241fromHandle h = fromStream go
222242 where
@@ -238,6 +258,8 @@ fromHandle h = fromStream go
238258-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
239259-- [1,2,3]
240260-- @
261+--
262+-- @since 0.1.0
241263foldr :: Monad m => (a -> b -> b) -> b -> StreamT m a -> m b
242264foldr step acc m = go (toStream m)
243265 where
@@ -254,6 +276,8 @@ foldr step acc m = go (toStream m)
254276-- >> runIdentity $ foldrM (\\x xs -> return (x : xs)) [] (serially $ fromFoldable [1,2,3])
255277-- [1,2,3]
256278-- @
279+--
280+-- @since 0.2.0
257281{-# INLINE foldrM #-}
258282foldrM :: Monad m => (a -> b -> m b) -> b -> StreamT m a -> m b
259283foldrM step acc m = go (toStream m)
@@ -268,6 +292,8 @@ foldrM step acc m = go (toStream m)
268292-- user supplied extraction function (the third argument) at each step. This is
269293-- designed to work with the @foldl@ library. The suffix @x@ is a mnemonic for
270294-- extraction.
295+--
296+-- @since 0.2.0
271297{-# INLINE scanx #-}
272298scanx :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
273299scanx step begin done m = cons (done begin) $ fromStream $ go (toStream m) begin
@@ -279,6 +305,8 @@ scanx step begin done m = cons (done begin) $ fromStream $ go (toStream m) begin
279305 in yld (done s) (go r s)
280306 in S.runStream m1 Nothing stp single yield
281307
308+-- |
309+-- @since 0.1.1
282310{-# DEPRECATED scan "Please use scanx instead." #-}
283311scan :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
284312scan = scanx
@@ -287,6 +315,8 @@ scan = scanx
287315-- step, generating a stream of all intermediate fold results. The first
288316-- element of the stream is the user supplied initial value, and the last
289317-- element of the stream is the same as the result of 'foldl''.
318+--
319+-- @since 0.2.0
290320{-# INLINE scanl' #-}
291321scanl' :: IsStream t => (b -> a -> b) -> b -> t m a -> t m b
292322scanl' step begin m = scanx step begin id m
@@ -295,6 +325,8 @@ scanl' step begin m = scanx step begin id m
295325-- left fold, but applies a user supplied extraction function (the third
296326-- argument) to the folded value at the end. This is designed to work with the
297327-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
328+--
329+-- @since 0.2.0
298330{-# INLINE foldx #-}
299331foldx :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
300332foldx step begin done m = get $ go (toStream m) begin
@@ -316,17 +348,23 @@ foldx step begin done m = get $ go (toStream m) begin
316348 in (S.runStream stream) Nothing undefined sng yld
317349 in (S.runStream m1) Nothing stop single yield
318350
351+-- |
352+-- @since 0.1.0
319353{-# DEPRECATED foldl "Please use foldx instead." #-}
320354foldl :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
321355foldl = foldx
322356
323357-- | Strict left associative fold.
358+--
359+-- @since 0.2.0
324360{-# INLINE foldl' #-}
325361foldl' :: Monad m => (b -> a -> b) -> b -> StreamT m a -> m b
326362foldl' step begin m = foldx step begin id m
327363
328364-- XXX replace the recursive "go" with explicit continuations.
329365-- | Like 'foldx', but with a monadic step function.
366+--
367+-- @since 0.2.0
330368foldxM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
331369foldxM step begin done m = go begin (toStream m)
332370 where
@@ -336,17 +374,23 @@ foldxM step begin done m = go begin (toStream m)
336374 yield a r = acc >>= \b -> go (step b a) r
337375 in (S.runStream m1) Nothing stop single yield
338376
377+-- |
378+-- @since 0.1.0
339379{-# DEPRECATED foldlM "Please use foldxM instead." #-}
340380foldlM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
341381foldlM = foldxM
342382
343383-- | Like 'foldl'' but with a monadic step function.
384+--
385+-- @since 0.2.0
344386foldlM' :: Monad m => (b -> a -> m b) -> b -> StreamT m a -> m b
345387foldlM' step begin m = foldxM step (return begin) return m
346388
347389-- | Decompose a stream into its head and tail. If the stream is empty, returns
348390-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
349391-- the head of the stream and 'ma' its tail.
392+--
393+-- @since 0.1.0
350394uncons :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (a, t m a))
351395uncons m =
352396 let stop = return Nothing
@@ -355,6 +399,8 @@ uncons m =
355399 in (S.runStream (toStream m)) Nothing stop single yield
356400
357401-- | Write a stream of Strings to an IO Handle.
402+--
403+-- @since 0.1.0
358404toHandle :: MonadIO m => IO.Handle -> StreamT m String -> m ()
359405toHandle h m = go (toStream m)
360406 where
@@ -369,11 +415,15 @@ toHandle h m = go (toStream m)
369415------------------------------------------------------------------------------
370416
371417-- | Convert a stream into a list in the underlying monad.
418+--
419+-- @since 0.1.0
372420{-# INLINABLE toList #-}
373421toList :: Monad m => StreamT m a -> m [a]
374422toList = foldrM (\a xs -> return (a : xs)) []
375423
376424-- | Take first 'n' elements from the stream and discard the rest.
425+--
426+-- @since 0.1.0
377427{-# INLINE take #-}
378428take :: IsStream t => Int -> t m a -> t m a
379429take n m = fromStream $ go n (toStream m)
@@ -383,6 +433,8 @@ take n m = fromStream $ go n (toStream m)
383433 in if n1 <= 0 then stp else (S.runStream m1) ctx stp sng yield
384434
385435-- | Include only those elements that pass a predicate.
436+--
437+-- @since 0.1.0
386438{-# INLINE filter #-}
387439filter :: IsStream t => (a -> Bool) -> t m a -> t m a
388440filter p m = fromStream $ go (toStream m)
@@ -395,6 +447,8 @@ filter p m = fromStream $ go (toStream m)
395447 in (S.runStream m1) ctx stp single yield
396448
397449-- | End the stream as soon as the predicate fails on an element.
450+--
451+-- @since 0.1.0
398452{-# INLINE takeWhile #-}
399453takeWhile :: IsStream t => (a -> Bool) -> t m a -> t m a
400454takeWhile p m = fromStream $ go (toStream m)
@@ -407,6 +461,8 @@ takeWhile p m = fromStream $ go (toStream m)
407461 in (S.runStream m1) ctx stp single yield
408462
409463-- | Discard first 'n' elements from the stream and take the rest.
464+--
465+-- @since 0.1.0
410466drop :: IsStream t => Int -> t m a -> t m a
411467drop n m = fromStream $ go n (toStream m)
412468 where
@@ -420,6 +476,8 @@ drop n m = fromStream $ go n (toStream m)
420476
421477-- | Drop elements in the stream as long as the predicate succeeds and then
422478-- take the rest of the stream.
479+--
480+-- @since 0.1.0
423481{-# INLINE dropWhile #-}
424482dropWhile :: IsStream t => (a -> Bool) -> t m a -> t m a
425483dropWhile p m = fromStream $ go (toStream m)
@@ -432,6 +490,8 @@ dropWhile p m = fromStream $ go (toStream m)
432490 in (S.runStream m1) ctx stp single yield
433491
434492-- | Determine whether all elements of a stream satisfy a predicate.
493+--
494+-- @since 0.1.0
435495all :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
436496all p m = go (toStream m)
437497 where
@@ -443,6 +503,8 @@ all p m = go (toStream m)
443503 in (S.runStream m1) Nothing (return True) single yield
444504
445505-- | Determine whether any of the elements of a stream satisfy a predicate.
506+--
507+-- @since 0.1.0
446508any :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
447509any p m = go (toStream m)
448510 where
@@ -454,14 +516,20 @@ any p m = go (toStream m)
454516 in (S.runStream m1) Nothing (return False) single yield
455517
456518-- | Determine the sum of all elements of a stream of numbers
519+--
520+-- @since 0.1.0
457521sum :: (Monad m, Num a) => StreamT m a -> m a
458522sum = foldl (+) 0 id
459523
460524-- | Determine the product of all elements of a stream of numbers
525+--
526+-- @since 0.1.1
461527product :: (Monad m, Num a) => StreamT m a -> m a
462528product = foldl (*) 1 id
463529
464530-- | Extract the first element of the stream, if any.
531+--
532+-- @since 0.1.0
465533head :: Monad m => StreamT m a -> m (Maybe a)
466534head m =
467535 let stop = return Nothing
@@ -470,6 +538,8 @@ head m =
470538 in (S.runStream (toStream m)) Nothing stop single yield
471539
472540-- | Extract all but the first element of the stream, if any.
541+--
542+-- @since 0.1.1
473543tail :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (t m a))
474544tail m =
475545 let stop = return Nothing
@@ -478,11 +548,15 @@ tail m =
478548 in (S.runStream (toStream m)) Nothing stop single yield
479549
480550-- | Extract the last element of the stream, if any.
551+--
552+-- @since 0.1.1
481553{-# INLINE last #-}
482554last :: Monad m => StreamT m a -> m (Maybe a)
483555last = foldl (\_ y -> Just y) Nothing id
484556
485557-- | Determine whether the stream is empty.
558+--
559+-- @since 0.1.1
486560null :: Monad m => StreamT m a -> m Bool
487561null m =
488562 let stop = return True
@@ -491,6 +565,8 @@ null m =
491565 in (S.runStream (toStream m)) Nothing stop single yield
492566
493567-- | Determine whether an element is present in the stream.
568+--
569+-- @since 0.1.0
494570elem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
495571elem e m = go (toStream m)
496572 where
@@ -501,6 +577,8 @@ elem e m = go (toStream m)
501577 in (S.runStream m1) Nothing stop single yield
502578
503579-- | Determine whether an element is not present in the stream.
580+--
581+-- @since 0.1.0
504582notElem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
505583notElem e m = go (toStream m)
506584 where
@@ -511,11 +589,15 @@ notElem e m = go (toStream m)
511589 in (S.runStream m1) Nothing stop single yield
512590
513591-- | Determine the length of the stream.
592+--
593+-- @since 0.1.0
514594length :: Monad m => StreamT m a -> m Int
515595length = foldl (\n _ -> n + 1) 0 id
516596
517597-- | Returns the elements of the stream in reverse order.
518598-- The stream must be finite.
599+--
600+-- @since 0.1.1
519601reverse :: (IsStream t) => t m a -> t m a
520602reverse m = fromStream $ go S.nil (toStream m)
521603 where
@@ -528,6 +610,8 @@ reverse m = fromStream $ go S.nil (toStream m)
528610
529611-- XXX replace the recursive "go" with continuation
530612-- | Determine the minimum element in a stream.
613+--
614+-- @since 0.1.0
531615minimum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
532616minimum m = go Nothing (toStream m)
533617 where
@@ -543,6 +627,8 @@ minimum m = go Nothing (toStream m)
543627
544628-- XXX replace the recursive "go" with continuation
545629-- | Determine the maximum element in a stream.
630+--
631+-- @since 0.1.0
546632maximum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
547633maximum m = go Nothing (toStream m)
548634 where
@@ -564,6 +650,8 @@ maximum m = go Nothing (toStream m)
564650
565651-- | Replace each element of the stream with the result of a monadic action
566652-- applied on the element.
653+--
654+-- @since 0.1.0
567655{-# INLINE mapM #-}
568656mapM :: (IsStream t, Monad m) => (a -> m b) -> t m a -> t m b
569657mapM f m = fromStream $ go (toStream m)
@@ -575,6 +663,8 @@ mapM f m = fromStream $ go (toStream m)
575663
576664-- | Apply a monadic action to each element of the stream and discard the
577665-- output of the action.
666+--
667+-- @since 0.1.0
578668mapM_ :: Monad m => (a -> m b) -> StreamT m a -> m ()
579669mapM_ f m = go (toStream m)
580670 where
@@ -586,6 +676,8 @@ mapM_ f m = go (toStream m)
586676
587677-- | Reduce a stream of monadic actions to a stream of the output of those
588678-- actions.
679+--
680+-- @since 0.1.0
589681sequence :: (IsStream t, Monad m) => t m (m a) -> t m a
590682sequence m = fromStream $ go (toStream m)
591683 where
@@ -599,10 +691,14 @@ sequence m = fromStream $ go (toStream m)
599691------------------------------------------------------------------------------
600692
601693-- | Zip two streams serially using a pure zipping function.
694+--
695+-- @since 0.1.0
602696zipWith :: IsStream t => (a -> b -> c) -> t m a -> t m b -> t m c
603697zipWith f m1 m2 = fromStream $ S.zipWith f (toStream m1) (toStream m2)
604698
605699-- | Zip two streams serially using a monadic zipping function.
700+--
701+-- @since 0.1.0
606702zipWithM :: IsStream t => (a -> b -> t m c) -> t m a -> t m b -> t m c
607703zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
608704 where
@@ -622,11 +718,15 @@ zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
622718
623719-- | Zip two streams concurrently (i.e. both the elements being zipped are
624720-- generated concurrently) using a pure zipping function.
721+--
722+-- @since 0.2.0
625723zipParallelWith :: (IsStream t, MonadParallel m)
626724 => (a -> b -> c) -> t m a -> t m b -> t m c
627725zipParallelWith f m1 m2 =
628726 fromStream $ S.zipParallelWith f (toStream m1) (toStream m2)
629727
728+-- |
729+-- @since 0.1.0
630730{-# DEPRECATED zipAsyncWith "Please use zipParallelWith instead." #-}
631731zipAsyncWith :: (IsStream t, MonadParallel m)
632732 => (a -> b -> c) -> t m a -> t m b -> t m c
@@ -634,6 +734,8 @@ zipAsyncWith = zipParallelWith
634734
635735-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
636736-- concurrently) using a monadic zipping function.
737+--
738+-- @since 0.2.0
637739zipParallelWithM :: (IsStream t, MonadParallel m)
638740 => (a -> b -> t m c) -> t m a -> t m b -> t m c
639741zipParallelWithM f m1 m2 = fromStream $ Stream $ \_ stp sng yld -> do
@@ -641,6 +743,8 @@ zipParallelWithM f m1 m2 = fromStream $ Stream $ \_ stp sng yld -> do
641743 mb <- async m2
642744 (S.runStream (toStream (zipWithM f ma mb))) Nothing stp sng yld
643745
746+-- |
747+-- @since 0.1.0
644748{-# DEPRECATED zipAsyncWithM "Please use zipParallelWithM instead." #-}
645749zipAsyncWithM :: (IsStream t, MonadParallel m)
646750 => (a -> b -> t m c) -> t m a -> t m b -> t m c