@@ -126,6 +126,25 @@
126-- or to not be able to use `take 0` if we have it. Also, applicative and
126-- or to not be able to use `take 0` if we have it. Also, applicative and
127-- monadic composition of folds would not be possible.
127-- monadic composition of folds would not be possible.
131+-- Fold may use other folds in the downstream pipeline. When a fold is done and
132+-- it wants to terminate it needs to wait for the downstream folds before it
133+-- returns. For example, if the downstream fold is an async fold we need to
134+-- wait for the async fold to finish and return the final result.
136+-- To be able to support this use case we need a cleanup action in the fold.
137+-- The fold gets finalized once the cleanup is called and we can use extract to
138+-- get the final state/result of the fold.
140+-- Similar to folds we may have a cleanup action in streams as well. Currently,
141+-- we rely on GC to cleanup the streams, if we use a cleanup action then we can
142+-- perform cleanup quickly. Also, similar to folds we can also have an
143+-- "initial" action in streams as well to generate the initial state. It could
144+-- decouple the initialization of the stream from the first element being
145+-- pulled. For example, you may want to start a timer at initialization rather
146+-- than at the first element pull of the stream.
129-- == Terminating Folds with backtracking
148-- == Terminating Folds with backtracking
131-- Consider the example of @takeWhile@ operation, it needs to inspect an
150-- Consider the example of @takeWhile@ operation, it needs to inspect an