Skip to content

Commit 20bbea6

Browse files
authored
+ filterM and filter
1 parent 3dfad1c commit 20bbea6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/FSharpPlus/List.fs

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ module ListT =
123123
| Nil -> return Nil
124124
else return Nil }
125125
loop count (input: ListT<'MT>)
126+
127+
let inline filterM (f: 'T -> ListT<'``M<bool>``>) (input: ListT<'MT>) : ListT<'MT> =
128+
input |> ListT.bind (fun v -> f v |> ListT.bind (fun b -> if b then singleton v else empty ()))
129+
130+
let inline filter f (input: ListT<'MT>) : ListT<'MT> = filterM (f >> singleton) input
126131

127132
let inline run (lst: ListT<'MT>) : '``Monad<list<'T>>`` =
128133
let rec loop acc x = unwrap x >>= function

0 commit comments

Comments
 (0)