@@ -91,26 +91,37 @@
91-- = Folds vs. Streams
91-- = Folds vs. Streams
93-- We can often use streams or folds to achieve the same goal. However, streams
93-- We can often use streams or folds to achieve the same goal. However, streams
94−-- allow efficient composition of producers (e.g. 'Streamly.Prelude.serial' or
94+-- are more efficient in composition of producers (e.g.
95−-- 'Streamly.Prelude.mergeBy') whereas folds allow efficient composition of
95+-- 'Streamly.Prelude.serial' or 'Streamly.Prelude.mergeBy') whereas folds are
96−-- consumers (e.g. 'serialWith', 'partition' or 'teeWith').
96+-- more efficient in composition of consumers (e.g. 'serialWith', 'partition'
98-- Streams are producers, transformations on streams happen on the output side:
99-- Streams are producers, transformations on streams happen on the output side:
100−-- >>> f = Stream.sum . Stream.map (+1) . Stream.filter odd
104+-- & Stream.map (+1)
101-- >>> f $ Stream.fromList [1..100]
107-- >>> f $ Stream.fromList [1..100]
104-- Folds are stream consumers with an input stream and an output value, stream
110-- Folds are stream consumers with an input stream and an output value, stream
105-- transformations on folds happen on the input side:
111-- transformations on folds happen on the input side:
107−-- >>> f = Fold.filter odd $ Fold.lmap (+1) $ Fold.sum
115+-- Fold.filter odd
108-- >>> Stream.fold f $ Stream.fromList [1..100]
119-- >>> Stream.fold f $ Stream.fromList [1..100]
122+-- Notice the similiarity in the definition of @f@ in both cases, the only
111−-- Notice the composition by @.@ vs @$@ and the order of operations in the
123+-- difference is the composition by @&@ vs @$@ and the use @lmap@ vs @map@, the
112−-- above examples, the difference is due to output vs input side
124+-- difference is due to output vs input side transformations.
115module Streamly.Data.Fold
126module Streamly.Data.Fold