From df6c0744dc4ebd164cd8a309eef5d2798b2d3e90 Mon Sep 17 00:00:00 2001 From: Estevan Castilho Date: Sat, 24 Oct 2026 03:16:19 +0000 Subject: Monadic `concat_mapm` --- lib/Utilities.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/Utilities.ml') diff --git a/lib/Utilities.ml b/lib/Utilities.ml index dcf4417..6f27b30 100644 --- a/lib/Utilities.ml +++ b/lib/Utilities.ml @@ -55,7 +55,7 @@ module List = struct include Generic (ListSequence) - let concat_map f xs = List.map f xs |> sequence |> Stdlib.Result.map List.concat + let concat_mapm f xs = List.map f xs |> sequence |> Stdlib.Result.map List.concat let hd_opt = function x :: _ -> Some x | [] -> None end @@ -93,6 +93,8 @@ module FingerTree = struct match f elem with None -> acc | Some result -> BatFingerTree.snoc acc result) BatFingerTree.empty + let concat_mapm f xs = BatFingerTree.map f xs |> sequence |> Stdlib.Result.map BatFingerTree.append + let concat_map f = BatFingerTree.fold_left (fun acc elem -> BatFingerTree.append acc @@ f elem) BatFingerTree.empty -- cgit v1.2.3