[utils] add find_mapi_opt utility

Reviewed By: jeremydubreil

Differential Revision: D3851678

fbshipit-source-id: dcf1c6d
master
Sam Blackshear 8 years ago committed by Facebook Github Bot 4
parent ef8b215ee1
commit 4f8370e524

@ -221,6 +221,17 @@ let rec find_map_opt f = function
then e'
else find_map_opt f l'
(** Like find_map_opt, but with indices *)
let find_mapi_opt (f : int -> 'a -> 'b option) l =
let rec find_mapi_opt_ f i = function
| [] -> None
| e :: l' ->
let e' = f i e in
if e' <> None
then e'
else find_mapi_opt_ f (i + 1) l' in
find_mapi_opt_ f 0 l
let to_string f l =
let rec aux l =
match l with

@ -112,4 +112,7 @@ val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
(** Return the first non-None result found when applying f to elements of l *)
val find_map_opt : ('a -> 'b option) -> 'a list -> 'b option
(** Like find_map_opt, but with indices *)
val find_mapi_opt : (int -> 'a -> 'b option) -> 'a list -> 'b option
val to_string : ('a -> string) -> 'a list -> string

Loading…
Cancel
Save