File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
core/src/Streamly/Internal/Data/Fold Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 126126-- or to not be able to use `take 0` if we have it. Also, applicative and
127127-- monadic composition of folds would not be possible.
128128--
129+ -- == Cleanup Action
130+ --
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.
135+ --
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.
139+ --
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.
147+ --
129148-- == Terminating Folds with backtracking
130149--
131150-- Consider the example of @takeWhile@ operation, it needs to inspect an
You can’t perform that action at this time.
0 commit comments