mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
factor implem for Vec.{find,find_i}
This commit is contained in:
parent
cad41d70d6
commit
2fda76a5f7
2 changed files with 6 additions and 18 deletions
|
|
@ -475,21 +475,6 @@ let for_all p v =
|
|||
|
||||
let member ~eq x v = exists (eq x) v
|
||||
|
||||
let find_internal_ p v =
|
||||
let n = v.size in
|
||||
let rec check i =
|
||||
if i = n then
|
||||
raise_notrace Not_found
|
||||
else (
|
||||
let x = v.vec.(i) in
|
||||
if p x then
|
||||
x
|
||||
else
|
||||
check (i + 1)
|
||||
)
|
||||
in
|
||||
check 0
|
||||
|
||||
let find_internal_i_ p v =
|
||||
let n = v.size in
|
||||
let rec check i =
|
||||
|
|
@ -505,8 +490,10 @@ let find_internal_i_ p v =
|
|||
in
|
||||
check 0
|
||||
|
||||
let find_exn p v = try find_internal_ p v with Not_found -> raise Not_found
|
||||
let find p v = try Some (find_internal_ p v) with Not_found -> None
|
||||
let find_exn p v =
|
||||
try snd (find_internal_i_ p v) with Not_found -> raise Not_found
|
||||
|
||||
let find p v = try Some (snd @@ find_internal_i_ p v) with Not_found -> None
|
||||
let findi p v = try Some (find_internal_i_ p v) with Not_found -> None
|
||||
|
||||
let find_map f v =
|
||||
|
|
|
|||
|
|
@ -221,7 +221,8 @@ val find : ('a -> bool) -> ('a, _) t -> 'a option
|
|||
(** Find an element that satisfies the predicate. *)
|
||||
|
||||
val findi : ('a -> bool) -> ('a, _) t -> (int * 'a) option
|
||||
(** Find an element and its index that satisfies the predicate. *)
|
||||
(** Find an element and its index that satisfies the predicate.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val find_exn : ('a -> bool) -> ('a, _) t -> 'a
|
||||
(** Find an element that satisfies the predicate, or
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue