diff options
Diffstat (limited to 'lib/kernel/Generator.ml')
| -rw-r--r-- | lib/kernel/Generator.ml | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/kernel/Generator.ml b/lib/kernel/Generator.ml index b83de3b..a037b3d 100644 --- a/lib/kernel/Generator.ml +++ b/lib/kernel/Generator.ml @@ -53,3 +53,19 @@ class producer_cursor produce finally = end let cursor_of ?finally produce = new producer_cursor produce finally |> Protocols.Handle.make + +let filter keep cursor = + cursor_of + ~finally:(fun () -> Protocols.Handle.release cursor) + (fun ~yield -> + let open Utilities.Result in + let* scan = Protocols.Cursor.require cursor in + let rec pass () = + let* next = Protocols.Cursor.next scan in + match next with + | None -> Ok () + | Some tuple -> + if keep tuple then yield tuple; + pass () + in + pass () ) |
