
27 Dec
2014
27 Dec
'14
11:59 p.m.
Currently, filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a] filterM p = foldr go (return []) where go x r = do flg <- p x ys <- r return (if flg then x:ys else ys) We could change this to filterM :: (Applicative f) => (a -> f Bool) -> [a] -> f [a] filterM p = foldr go (pure []) where go x r = f <$> p x <*> r where f flg ys = if flg then x:ys else ys