Skip to content

Commit

Permalink
Use List.find_map (#9589)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojb authored May 21, 2020
1 parent a151e91 commit 9b74884
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ocamltest/ocaml_actions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions parsing/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions utils/misc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions utils/misc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b74884

Please sign in to comment.