Merge pull request #990 from ocaml/list-find-exn

Add List.find_exn
This commit is contained in:
Etienne Millon 2018-07-10 13:51:44 +02:00 committed by GitHub
commit 1c28d737e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 11 deletions

View File

@ -181,9 +181,10 @@ let find_root () =
List.fold_left l ~init:max_int ~f:(fun acc (prio, _, _) -> List.fold_left l ~init:max_int ~f:(fun acc (prio, _, _) ->
min acc prio) min acc prio)
in in
match List.find l ~f:(fun (prio, _, _) -> prio = lowest_priority) with let (_, dir, to_cwd) =
| None -> assert false List.find_exn l ~f:(fun (prio, _, _) -> prio = lowest_priority)
| Some (_, dir, to_cwd) -> (dir, to_cwd) in
(dir, to_cwd)
let package_name = let package_name =
Arg.conv ((fun p -> Ok (Package.Name.of_string p)), Package.Name.pp) Arg.conv ((fun p -> Ok (Package.Name.of_string p)), Package.Name.pp)
@ -896,11 +897,7 @@ let external_lib_deps =
in in
if only_missing then begin if only_missing then begin
let context = let context =
match List.find_exn setup.contexts ~f:(fun c -> c.name = context_name)
List.find setup.contexts ~f:(fun c -> c.name = context_name)
with
| None -> assert false
| Some c -> c
in in
let missing = let missing =
String.Map.filteri externals ~f:(fun name _ -> String.Map.filteri externals ~f:(fun name _ ->

View File

@ -160,9 +160,9 @@ module Internal_rule = struct
last_requested_file :: acc last_requested_file :: acc
else else
let requested_file, rev_dep = let requested_file, rev_dep =
Option.value_exn List.find_exn
(List.find t.rev_deps ~f:(fun (_, t) -> t.rev_deps
Id.Set.mem t.transitive_rev_deps last.id)) ~f:(fun (_, t) -> Id.Set.mem t.transitive_rev_deps last.id)
in in
build_loop (requested_file :: acc) rev_dep build_loop (requested_file :: acc) rev_dep
in in

View File

@ -77,6 +77,11 @@ let rec find l ~f =
| [] -> None | [] -> None
| x :: l -> if f x then Some x else find l ~f | x :: l -> if f x then Some x else find l ~f
let find_exn l ~f =
match find l ~f with
| Some x -> x
| None -> invalid_arg "List.find_exn"
let rec last = function let rec last = function
| [] -> None | [] -> None
| [x] -> Some x | [x] -> Some x

View File

@ -28,6 +28,7 @@ val rev_filter_partition_map
-> 'b t * 'c t -> 'b t * 'c t
val find : 'a t -> f:('a -> bool ) -> 'a option val find : 'a t -> f:('a -> bool ) -> 'a option
val find_exn : 'a t -> f:('a -> bool ) -> 'a
val find_map : 'a t -> f:('a -> 'b option) -> 'b option val find_map : 'a t -> f:('a -> 'b option) -> 'b option
val last : 'a t -> 'a option val last : 'a t -> 'a option