Skip to content

Commit 4650b6c

Browse files
committed
Added filterM
1 parent 9a4953b commit 4650b6c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
297297
```
298298

299299

300+
#### `filterM`
301+
302+
``` purescript
303+
filterM :: forall a m. (Monad m) => (a -> m Boolean) -> [a] -> m [a]
304+
```
305+
306+
300307

301308
## Module Control.MonadPlus
302309

src/Control/Monad.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ when false _ = return unit
1818
unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
1919
unless false m = m
2020
unless true _ = return unit
21+
22+
filterM :: forall a m. (Monad m) => (a -> m Boolean) -> [a] -> m [a]
23+
filterM _ [] = return []
24+
filterM p (x:xs) = do
25+
b <- p x
26+
xs' <- filterM p xs
27+
return $ if b
28+
then x : xs'
29+
else xs'

0 commit comments

Comments
 (0)