Skip to content

Instantly share code, notes, and snippets.



Last active Oct 31, 2017
What would you like to do?
fold : (Monad m) => (a -> b -> b) -> b -> Sink a m b
fold f = recur where
recur acc = do
ma <- await -- await for more inputs
case ma of
Just x => do -- in case there is a value to process
acc' <- f x acc -- * combine it the current accumulator
recur acc' -- * and recurse with the new value
Nothing => pure acc -- otherwise, return the result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment