Skip to content

Instantly share code, notes, and snippets.

@edsko
Last active July 24, 2019 14:07
Show Gist options
  • Save edsko/b0702d536ca552f8bd9d6ee506341aee to your computer and use it in GitHub Desktop.
Save edsko/b0702d536ca552f8bd9d6ee506341aee to your computer and use it in GitHub Desktop.
repeatedly :: (a -> b -> b) -> ([a] -> b -> b)
repeatedly = flip . foldl' . flip
repeatedlyM :: Monad m => (a -> b -> m b) -> ([a] -> b -> m b)
repeatedlyM = flip . foldlM' . flip
foldlM' :: forall m a b. Monad m => (b -> a -> m b) -> b -> [a] -> m b
foldlM' f e = go e
where
go :: b -> [a] -> m b
go acc [] = pure acc
go acc (a:as) = f acc a >>= \acc' -> go acc' as
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment