summaryrefslogtreecommitdiffstats
path: root/lib/prelude.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/prelude.ml')
-rw-r--r--lib/prelude.ml23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/prelude.ml b/lib/prelude.ml
index 57f7af3..f571a4d 100644
--- a/lib/prelude.ml
+++ b/lib/prelude.ml
@@ -16,6 +16,29 @@ module List = struct
16 go 16 go
17end 17end
18 18
19module Map = struct
20 include Map
21
22 let fold_result (m : ('k, 'v, _) t) ~(init : 'acc)
23 ~(f : key:'k -> data:'v -> 'acc -> ('acc, 'err) result) :
24 ('acc, 'err) result =
25 fold_until m ~init
26 ~f:(fun ~key ~data acc ->
27 match f ~key ~data acc with
28 | Ok acc' -> Continue acc'
29 | Error _ as res -> Stop res)
30 ~finish:(fun v -> Ok v)
31
32 let fold_option (m : ('k, 'v, _) t) ~(init : 'acc)
33 ~(f : key:'k -> data:'v -> 'acc -> 'acc option) : 'acc option =
34 fold_until m ~init
35 ~f:(fun ~key ~data acc ->
36 match f ~key ~data acc with
37 | Some acc' -> Continue acc'
38 | None -> Stop None)
39 ~finish:(fun v -> Some v)
40end
41
19module Z = struct 42module Z = struct
20 include Z 43 include Z
21 44