Utils: add first_some
This commit is contained in:
parent
62a1be15b7
commit
ec922f6821
@ -112,6 +112,11 @@ let unopt_list l =
|
|||||||
let may_cons xs x = match x with None -> xs | Some x -> x :: xs in
|
let may_cons xs x = match x with None -> xs | Some x -> x :: xs in
|
||||||
List.rev @@ List.fold_left may_cons [] l
|
List.rev @@ List.fold_left may_cons [] l
|
||||||
|
|
||||||
|
let first_some a b = match a, b with
|
||||||
|
| None, None -> None
|
||||||
|
| None, Some v -> Some v
|
||||||
|
| Some v, _ -> Some v
|
||||||
|
|
||||||
let filter_map f l =
|
let filter_map f l =
|
||||||
let may_cons xs x = match f x with None -> xs | Some x -> x :: xs in
|
let may_cons xs x = match f x with None -> xs | Some x -> x :: xs in
|
||||||
List.rev @@ List.fold_left may_cons [] l
|
List.rev @@ List.fold_left may_cons [] l
|
||||||
|
@ -31,6 +31,7 @@ val apply_option: f:('a -> 'b option) -> 'a option -> 'b option
|
|||||||
val iter_option: f:('a -> unit) -> 'a option -> unit
|
val iter_option: f:('a -> unit) -> 'a option -> unit
|
||||||
val unopt: 'a -> 'a option -> 'a
|
val unopt: 'a -> 'a option -> 'a
|
||||||
val unopt_list: 'a option list -> 'a list
|
val unopt_list: 'a option list -> 'a list
|
||||||
|
val first_some: 'a option -> 'a option -> 'a option
|
||||||
|
|
||||||
val display_paragraph: Format.formatter -> string -> unit
|
val display_paragraph: Format.formatter -> string -> unit
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user