Last active
October 31, 2017 13:59
-
-
Save deque-blog/d57efd532956dc64f7c611fc5ba2f8e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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