From 1ab69bfb730ebad450024918a43580e4aeb0d56d Mon Sep 17 00:00:00 2001 From: Estevan Castilho Date: Sat, 24 Oct 2026 02:47:52 +0000 Subject: Steal a `filter_map` implementation from Karuta --- lib/Utilities.ml | 6 ++++++ lib/Utilities.mli | 1 + 2 files changed, 7 insertions(+) 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 -- cgit v1.2.3