diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-10-24 02:47:52 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-10-24 03:35:40 +0000 |
| commit | 1ab69bfb730ebad450024918a43580e4aeb0d56d (patch) | |
| tree | a215ae17dfaef1fd016df05316742d311e001884 /lib | |
| parent | eb7ad043880a0a846864c7b648e59c2a29610c51 (diff) | |
| download | RNT-1ab69bfb730ebad450024918a43580e4aeb0d56d.tar.gz RNT-1ab69bfb730ebad450024918a43580e4aeb0d56d.zip | |
Steal a `filter_map` implementation from Karuta
Diffstat (limited to '')
| -rw-r--r-- | lib/Utilities.ml | 6 | ||||
| -rw-r--r-- | lib/Utilities.mli | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/Utilities.ml b/lib/Utilities.ml index 8f278a3..8b6b08e 100644 --- a/lib/Utilities.ml +++ b/lib/Utilities.ml @@ -86,6 +86,12 @@ module FingerTree = struct let join ss sep = BatFingerTree.print ~first:"" ~last:"" ~sep BatIO.nwrite |> Fun.flip BatIO.to_string ss + + let filter_map f = + BatFingerTree.fold_left + (fun acc elem -> + match f elem with None -> acc | Some result -> BatFingerTree.snoc acc result) + BatFingerTree.empty end module Atomic = struct diff --git a/lib/Utilities.mli b/lib/Utilities.mli index 204fec3..f220b08 100644 --- a/lib/Utilities.mli +++ b/lib/Utilities.mli @@ -35,6 +35,7 @@ module FingerTree : sig val sequence : ('a, 'b) result BatFingerTree.t -> ('a BatFingerTree.t, 'b) result val foldm_left : ('a -> 'b -> ('a, 'e) result) -> 'a -> 'b BatFingerTree.t -> ('a, 'e) result val join : string BatFingerTree.t -> string -> string + val filter_map : ('a -> 'b option) -> 'a BatFingerTree.t -> 'b BatFingerTree.t end module Fun : sig |
