Skip to content

Instantly share code, notes, and snippets.

@rgrinberg
Created January 12, 2017 17:30
Show Gist options
  • Save rgrinberg/5b82494f05d0b5a68c0f5d8da977dd0f to your computer and use it in GitHub Desktop.
Save rgrinberg/5b82494f05d0b5a68c0f5d8da977dd0f to your computer and use it in GitHub Desktop.
mapM' :: Monad m => (a -> m b) -> [a] -> m [b]
mapM' _ [] = return []
mapM' f (x : xs) = do
y <- f x
ys <- mapM' f xs
return (y : ys)
mapM'' :: Monad m => (a -> m b) -> [a] -> m [b]
mapM'' _ [] = return []
mapM'' f (x : xs) =
f x >>= \y ->
mapM'' f xs >>= \ys ->
return (y : ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment