diff --git a/infer/src/backend/iList.ml b/infer/src/backend/iList.ml index 6abbab2d0..1a534b3af 100644 --- a/infer/src/backend/iList.ml +++ b/infer/src/backend/iList.ml @@ -38,6 +38,11 @@ let fold_right f l a = let g x y = f y x in fold_left g a (rev l) +(** fold_left with indices *) +let fold_lefti (f : 'a -> int -> 'b -> 'a) a l = + fold_left (fun (i, acc) e -> i +1, f acc i e) (0, a) l + |> snd + (** tail-recursive variant of List.combine *) let combine = let rec combine acc l1 l2 = match l1, l2 with diff --git a/infer/src/backend/iList.mli b/infer/src/backend/iList.mli index 5c4377a2c..850f1551e 100644 --- a/infer/src/backend/iList.mli +++ b/infer/src/backend/iList.mli @@ -42,6 +42,9 @@ val length : 'a list -> int (** tail-recursive variant of List.fold_right *) val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b +(** fold_left with indices *) +val fold_lefti : ('a -> int -> 'b -> 'a) -> 'a -> 'b list -> 'a + (** tail-recursive variant of List.map *) val map : ('a -> 'b) -> 'a list -> 'b list