Commit 96a4062a authored by David Feuer's avatar David Feuer Committed by Joachim Breitner
Browse files

Make filterM a good consumer

analogously to mapM. Fixes #9546.
parent 78932109
......@@ -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 <=<, >=>
......
......@@ -77,7 +77,8 @@
second argument, so that the fusion RULES for it do not change the
semantics. (#9596)
* `scanr` and `mapAccumL` now take part in list fusion (#9355, #9502)
* `scanr`, `mapAccumL` and `filterM` now take part in list fusion (#9355,
#9502, #9546)
## 4.7.0.1 *Jul 2014*
......
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