Forked from robotlolita/control.monad.basics.ls
Last active
December 29, 2015 22:19
-
-
Save apaleslimghost/7735552 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
# ## Function: sequence | |
# | |
# Evaluates each action in sequence, left to right, collecting the | |
# results. | |
# | |
# + type: (Monad m) => m -> [m a] -> m [a] | |
export sequence = (m, ms) --> do | |
return ms.reduce perform, m.of [] | |
# where: | |
function perform(m1, m2) => do | |
x <- m1.chain | |
xs <- m2.chain | |
m.of x ++ xs |
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
-- | Evaluate each action in the sequence from left to right, | |
-- and collect the results. | |
sequence :: Monad m => [m a] -> m [a] | |
sequence ms = foldr k (return []) ms | |
where | |
k m m' = do { x <- m; xs <- m'; return (x:xs) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@killdream the
push
creates weird side effects