adding find_map_opt utility function

Reviewed By: jvillard

Differential Revision: D3316364

fbshipit-source-id: 9bd5153
master
Sam Blackshear 9 years ago committed by Facebook Github Bot 1
parent 3a7767213c
commit 8cff90ed21

@ -175,6 +175,15 @@ let map2 f l1 l2 =
| _ -> raise Fail in
go l1 l2 []
(** Return the first non-None result found when applying f to elements of l *)
let rec find_map_opt f = function
| [] -> None
| e :: l' ->
let e' = f e in
if e' <> None
then e'
else find_map_opt f l'
let to_string f l =
let rec aux l =
match l with

@ -97,4 +97,7 @@ exception Fail
(** Apply [f] to pairs of elements; raise [Fail] if the two lists have different lenghts. *)
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
val to_string : ('a -> string) -> 'a list -> string

Loading…
Cancel
Save