Commit ac7c738b authored by Richard Lupton's avatar Richard Lupton Committed by Marge Bot

Generalized MonadUtils folds to Foldable (#16969)

parent 5b713aa3
...@@ -32,7 +32,7 @@ import Control.Applicative ...@@ -32,7 +32,7 @@ import Control.Applicative
import Control.Monad import Control.Monad
import Control.Monad.Fix import Control.Monad.Fix
import Control.Monad.IO.Class import Control.Monad.IO.Class
import Data.Foldable (sequenceA_) import Data.Foldable (sequenceA_, foldr)
import Data.List (unzip4, unzip5, zipWith4) import Data.List (unzip4, unzip5, zipWith4)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -191,17 +191,16 @@ orM :: Monad m => m Bool -> m Bool -> m Bool ...@@ -191,17 +191,16 @@ orM :: Monad m => m Bool -> m Bool -> m Bool
orM m1 m2 = m1 >>= \x -> if x then return True else m2 orM m1 m2 = m1 >>= \x -> if x then return True else m2
-- | Monadic version of foldl -- | Monadic version of foldl
foldlM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a foldlM :: (Monad m, Foldable t) => (a -> b -> m a) -> a -> t b -> m a
foldlM = foldM foldlM = foldM
-- | Monadic version of foldl that discards its result -- | Monadic version of foldl that discards its result
foldlM_ :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m () foldlM_ :: (Monad m, Foldable t) => (a -> b -> m a) -> a -> t b -> m ()
foldlM_ = foldM_ foldlM_ = foldM_
-- | Monadic version of foldr -- | Monadic version of foldr
foldrM :: (Monad m) => (b -> a -> m a) -> a -> [b] -> m a foldrM :: (Monad m, Foldable t) => (b -> a -> m a) -> a -> t b -> m a
foldrM _ z [] = return z foldrM k z x = foldr (\x r -> r >>= k x) (pure z) x
foldrM k z (x:xs) = do { r <- foldrM k z xs; k x r }
-- | Monadic version of fmap specialised for Maybe -- | Monadic version of fmap specialised for Maybe
maybeMapM :: Monad m => (a -> m b) -> (Maybe a -> m (Maybe b)) maybeMapM :: Monad m => (a -> m b) -> (Maybe a -> m (Maybe b))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment