[sledge] Add List.foldi

Differential Revision: D29441163

fbshipit-source-id: e58b57072
master
Josh Berdine 3 years ago committed by Facebook GitHub Bot
parent 8678923ca2
commit df4ce19954

@ -57,6 +57,7 @@ let group_join_by ~eq ~hash = group_join_by ~eq ~hash
let fold xs init ~f = fold_left ~f:(fun s x -> f x s) ~init xs
let fold_left xs init ~f = fold_left ~f ~init xs
let fold_right xs init ~f = fold_right ~f ~init xs
let foldi xs init ~f = foldi ~f:(fun s i x -> f i x s) ~init xs
let reduce xs ~f =
match xs with [] -> None | x :: xs -> Some (fold ~f xs x)

@ -94,6 +94,7 @@ val group_join_by :
val fold : 'a list -> 's -> f:('a -> 's -> 's) -> 's
val fold_left : 'a list -> 's -> f:('s -> 'a -> 's) -> 's
val fold_right : 'a list -> 's -> f:('a -> 's -> 's) -> 's
val foldi : 'a t -> 's -> f:(int -> 'a -> 's -> 's) -> 's
val reduce : 'a t -> f:('a -> 'a -> 'a) -> 'a option
val fold_diagonal : 'a list -> 's -> f:('a -> 'a -> 's -> 's) -> 's
val fold_map : 'a t -> 's -> f:('a -> 's -> 'b * 's) -> 'b t * 's

Loading…
Cancel
Save