on master help sign in
Rearrange the elimination section
796bb22Harendra Kumar
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+3
@@ -206,6 +206,9 @@ import Prelude hiding
206-- individual elements and we can loop over them as we deem fit. For example,
206-- individual elements and we can loop over them as we deem fit. For example,
207-- this can be used to convert a streamly stream into other stream types.
207-- this can be used to convert a streamly stream into other stream types.
208--
208--
209+-- All the folds in this module can be expressed in terms of 'uncons', however
210+-- the specific implementations are generally more efficient.
211+--
209-- @since 0.1.0
212-- @since 0.1.0
210{-# INLINE uncons #-}
213{-# INLINE uncons #-}
211uncons :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (a, t m a))
214uncons :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (a, t m a))
src/Streamly/Prelude.hs+25−27
@@ -320,6 +320,8 @@
320module Streamly.Prelude
320module Streamly.Prelude
321 (
321 (
322 -- * Construction
322 -- * Construction
323+ -- | Functions ending in the general shape @b -> t m a@
324+
323 -- ** Primitives
325 -- ** Primitives
324 -- | Primitives to construct a stream from pure values or monadic actions.
326 -- | Primitives to construct a stream from pure values or monadic actions.
325 -- All other stream construction and generation combinators described later
327 -- All other stream construction and generation combinators described later
@@ -386,17 +388,22 @@ module Streamly.Prelude
386 , fromFoldableM
388 , fromFoldableM
387
389
388 -- * Elimination
390 -- * Elimination
391+ -- | Functions ending in the general shape @t m a -> m b@
392+
393+ -- ** Running a 'Fold'
394+ -- $runningfolds
395+
396+ , fold
397+ , foldMany
389
398
390 -- ** Deconstruction
399 -- ** Deconstruction
391− -- | It is easy to express all the folds in terms of the 'uncons' primitive,
400+ -- | Functions ending in the general shape @t m a -> m (b, t m a)@
392− -- however the specific implementations provided later are generally more
401+
393− -- efficient.
394− --
395 , uncons
402 , uncons
396 , tail
403 , tail
397 , init
404 , init
398
405
399− -- ** Folding
406+ -- ** General Folds
400-- | In imperative terms a fold can be considered as a loop over the stream
407-- | In imperative terms a fold can be considered as a loop over the stream
401-- that reduces the stream to a single value.
408-- that reduces the stream to a single value.
402-- Left and right folds both use a fold function @f@ and an identity element
409-- Left and right folds both use a fold function @f@ and an identity element
@@ -466,24 +473,19 @@ module Streamly.Prelude
466-- the previous step. However, it is possible to fold parts of the stream in
473-- the previous step. However, it is possible to fold parts of the stream in
467-- parallel and then combine the results using a monoid.
474-- parallel and then combine the results using a monoid.
468
475
469− -- ** Right Folds
476+ -- *** Right Folds
470 -- $rightfolds
477 -- $rightfolds
471 , foldrM
478 , foldrM
472 , foldr
479 , foldr
473
480
474− -- ** Left Folds
481+ -- *** Left Folds
475 -- $leftfolds
482 -- $leftfolds
476 , foldl'
483 , foldl'
477 , foldl1'
484 , foldl1'
478 , foldlM'
485 , foldlM'
479
486
480− -- ** Composable Left Folds
487+ -- ** Specific Folds
481− -- $runningfolds
482−
483− , fold
484− , foldMany
485−
486− -- ** Full Folds
488+ -- *** Full Folds
487 -- | Folds that are guaranteed to evaluate the whole stream.
489 -- | Folds that are guaranteed to evaluate the whole stream.
488
490
489 -- -- ** To Summary (Full Folds)
491 -- -- ** To Summary (Full Folds)
@@ -503,17 +505,7 @@ module Streamly.Prelude
503 , minimum
505 , minimum
504 , the
506 , the
505
507
506− -- ** Lazy Folds
507− --
508− -- | Folds that generate a lazy structure. Note that the generated
509− -- structure may not be lazy if the underlying monad is strict.
510−
511− -- -- ** To Containers (Full Folds)
512− -- -- | Convert or divert a stream into an output structure, container or
513− -- sink.
514− , toList
515−
516− -- ** Partial Folds
508+ -- *** Partial Folds
517 -- | Folds that may terminate before evaluating the whole stream. These
509 -- | Folds that may terminate before evaluating the whole stream. These
518 -- folds strictly evaluate the stream until the result is determined.
510 -- folds strictly evaluate the stream until the result is determined.
519
511
@@ -540,6 +532,14 @@ module Streamly.Prelude
540 , and
532 , and
541 , or
533 , or
542
534
535+ -- *** To Containers
536+ -- | Convert a stream into a container holding all the values.
537+ , toList
538+
539+ -- ** Folding Concurrently
540+ , (|$.)
541+ , (|&.)
542+
543 -- ** Multi-Stream folds
543 -- ** Multi-Stream folds
544 , eqBy
544 , eqBy
545 , cmpBy
545 , cmpBy
@@ -553,8 +553,6 @@ module Streamly.Prelude
553 -- $application
553 -- $application
554 , (|$)
554 , (|$)
555 , (|&)
555 , (|&)
556− , (|$.)
557− , (|&.)
558
556
559 -- * Transformation
557 -- * Transformation
560
558