diff options
Diffstat (limited to 'libraries/base/Control/Monad.hs')
-rw-r--r-- | libraries/base/Control/Monad.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libraries/base/Control/Monad.hs b/libraries/base/Control/Monad.hs index 619a2bad94..db46dea699 100644 --- a/libraries/base/Control/Monad.hs +++ b/libraries/base/Control/Monad.hs @@ -93,12 +93,14 @@ guard False = empty -- | This generalizes the list-based 'filter' function. +{-# INLINE filterM #-} filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a] -filterM _ [] = return [] -filterM p (x:xs) = do - flg <- p x - ys <- filterM p xs - return (if flg then x:ys else ys) +filterM p = foldr go (return []) + where + go x r = do + flg <- p x + ys <- r + return (if flg then x:ys else ys) infixr 1 <=<, >=> |