File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -490,8 +490,24 @@ let find_internal_ p v =
490490 in
491491 check 0
492492
493+ let find_internal_i_ p v =
494+ let n = v.size in
495+ let rec check i =
496+ if i = n then
497+ raise_notrace Not_found
498+ else (
499+ let x = v.vec.(i) in
500+ if p x then
501+ i,x
502+ else
503+ check (i + 1 )
504+ )
505+ in
506+ check 0
507+
493508let find_exn p v = try find_internal_ p v with Not_found -> raise Not_found
494509let find p v = try Some (find_internal_ p v) with Not_found -> None
510+ let findi p v = try Some (find_internal_i_ p v) with Not_found -> None
495511
496512let find_map f v =
497513 let n = v.size in
Original file line number Diff line number Diff line change @@ -220,6 +220,9 @@ val for_all : ('a -> bool) -> ('a, _) t -> bool
220220val find : ('a -> bool ) -> ('a , _ ) t -> 'a option
221221(* * Find an element that satisfies the predicate. *)
222222
223+ val findi : ('a -> bool ) -> ('a , _ ) t -> (int * 'a ) option
224+ (* * Find an element and its index that satisfies the predicate. *)
225+
223226val find_exn : ('a -> bool ) -> ('a , _ ) t -> 'a
224227(* * Find an element that satisfies the predicate, or
225228 @raise Not_found if no element does. *)
You can’t perform that action at this time.
0 commit comments