aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util.ml7
-rw-r--r--lib/util.mli1
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml
index 5a02ffaef..0f5b3dbf5 100644
--- a/lib/util.ml
+++ b/lib/util.ml
@@ -121,6 +121,13 @@ let list_assign l n e =
in
assrec [] (l,n)
+let list_map_left f = (* ensures the order in case of side-effects *)
+ let rec map_rec = function
+ | [] -> []
+ | x::l -> let v = f x in v :: map_rec l
+ in
+ map_rec
+
let list_map_i f =
let rec map_i_rec i = function
| [] -> []
diff --git a/lib/util.mli b/lib/util.mli
index 60504d9cf..2ed595ef1 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -65,6 +65,7 @@ val list_tabulate : (int -> 'a) -> int -> 'a list
val list_assign : 'a list -> int -> 'a -> 'a list
val list_distinct : 'a list -> bool
val list_filter2 : ('a -> 'b -> bool) -> 'a list * 'b list -> 'a list * 'b list
+val list_map_left : ('a -> 'b) -> 'a list -> 'b list
val list_map_i : (int -> 'a -> 'b) -> int -> 'a list -> 'b list
val list_map2_i :
(int -> 'a -> 'b -> 'c) -> int -> 'a list -> 'b list -> 'c list