[utils] add fold_left_i utility

Reviewed By: jeremydubreil

Differential Revision: D3851332

fbshipit-source-id: a5649e7
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 55a46d1211
commit ef8b215ee1

@ -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

@ -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

Loading…
Cancel
Save