Use List.find_map (#9589)

master
Nicolás Ojeda Bär 2020-05-21 08:51:16 +02:00 committed by GitHub
parent a151e9187b
commit 9b748843bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 16 deletions

View File

@ -206,7 +206,7 @@ let cmas_need_dynamic_loading directories libraries =
begin try close_in ic with Sys_error _ -> () end;
Some (Error ("Corrupt or non-CMA file: " ^ library))
in
Misc.Stdlib.List.find_map loads_c_code (String.words libraries)
List.find_map loads_c_code (String.words libraries)
let compile_program ocamlsrcdir (compiler : Ocaml_compilers.compiler) log env =
let program_variable = compiler#program_variable in

View File

@ -294,19 +294,19 @@ struct
List.exists (fun ((_, s), (_, e)) -> s <= pos && pos <= e) iset
let find_bound_in iset ~range:(start, end_) =
Misc.Stdlib.List.find_map (fun ((a, x), (b, y)) ->
List.find_map (fun ((a, x), (b, y)) ->
if start <= x && x <= end_ then Some (a, x)
else if start <= y && y <= end_ then Some (b, y)
else None
) iset
let is_start iset ~pos =
Misc.Stdlib.List.find_map (fun ((a, x), _) ->
List.find_map (fun ((a, x), _) ->
if pos = x then Some a else None
) iset
let is_end iset ~pos =
Misc.Stdlib.List.find_map (fun (_, (b, y)) ->
List.find_map (fun (_, (b, y)) ->
if pos = y then Some b else None
) iset

View File

@ -110,14 +110,6 @@ module Stdlib = struct
| (hd1 :: tl1, hd2 :: tl2) -> eq hd1 hd2 && equal eq tl1 tl2
| (_, _) -> false
let rec find_map f = function
| x :: xs ->
begin match f x with
| None -> find_map f xs
| Some _ as y -> y
end
| [] -> None
let map2_prefix f l1 l2 =
let rec aux acc l1 l2 =
match l1, l2 with

View File

@ -97,10 +97,6 @@ module Stdlib : sig
(** Returns [true] iff the given lists have the same length and content
with respect to the given equality function. *)
val find_map : ('a -> 'b option) -> 'a t -> 'b option
(** [find_map f l] returns the first evaluation of [f] that returns [Some],
or returns None if there is no such element. *)
val some_if_all_elements_are_some : 'a option t -> 'a t option
(** If all elements of the given list are [Some _] then [Some xs]
is returned with the [xs] being the contents of those [Some]s, with