File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -297,6 +297,19 @@ unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
297
297
```
298
298
299
299
300
+ #### ` filterM `
301
+
302
+ ``` purescript
303
+ filterM :: forall a m. (Monad m) => (a -> m Boolean) -> [a] -> m [a]
304
+ ```
305
+
306
+ Filter where the predicate returns a monadic Boolean. For example:
307
+
308
+ ``` purescript
309
+ powerSet :: forall a. [a] -> [[a]]
310
+ powerSet = filterM (const [true, false])
311
+ ```
312
+
300
313
301
314
## Module Control.MonadPlus
302
315
Original file line number Diff line number Diff line change @@ -18,3 +18,18 @@ when false _ = return unit
18
18
unless :: forall m . (Monad m ) => Boolean -> m Unit -> m Unit
19
19
unless false m = m
20
20
unless true _ = return unit
21
+
22
+ -- | Filter where the predicate returns a monadic Boolean. For example:
23
+ -- |
24
+ -- | ```purescript
25
+ -- | powerSet :: forall a. [a] -> [[a]]
26
+ -- | powerSet = filterM (const [true, false])
27
+ -- | ```
28
+ filterM :: forall a m . (Monad m ) => (a -> m Boolean ) -> [a ] -> m [a ]
29
+ filterM _ [] = return []
30
+ filterM p (x:xs) = do
31
+ b <- p x
32
+ xs' <- filterM p xs
33
+ return $ if b
34
+ then x : xs'
35
+ else xs'
You can’t perform that action at this time.
0 commit comments