mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add CCArray.find_map{,_i}, deprecated older names (closes #129)
This commit is contained in:
parent
bfefda632b
commit
5d768aeeb2
2 changed files with 21 additions and 8 deletions
|
|
@ -212,11 +212,13 @@ let rec find_aux f a i =
|
|||
| Some _ as res -> res
|
||||
| None -> find_aux f a (i+1)
|
||||
|
||||
let find f a =
|
||||
find_aux (fun _ -> f ) a 0
|
||||
let find_map f a = find_aux (fun _ -> f ) a 0
|
||||
|
||||
let findi f a =
|
||||
find_aux f a 0
|
||||
let find = find_map
|
||||
|
||||
let find_map_i f a = find_aux f a 0
|
||||
|
||||
let findi = find_map_i
|
||||
|
||||
let find_idx p a =
|
||||
find_aux (fun i x -> if p x then Some (i,x) else None) a 0
|
||||
|
|
|
|||
|
|
@ -88,13 +88,24 @@ val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array
|
|||
[lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)]
|
||||
@since 1.0 *)
|
||||
|
||||
val find_map : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find_map f a] returns [Some y] if there is an element [x] such
|
||||
that [f x = Some y], else it returns [None]
|
||||
@since NEXT_RELEASE
|
||||
*)
|
||||
|
||||
val find : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find f a] returns [Some y] if there is an element [x] such
|
||||
that [f x = Some y], else it returns [None] *)
|
||||
(** Alias to {!find_map}
|
||||
@deprecated since NEXT_RELEASE *)
|
||||
|
||||
val find_map_i : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
(** Like {!find_map}, but also pass the index to the predicate function.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
(** Like {!find}, but also pass the index to the predicate function.
|
||||
@since 0.3.4 *)
|
||||
(** Alias to {!find_map_i}
|
||||
@since 0.3.4
|
||||
@deprecated since NEXT_RELEASE *)
|
||||
|
||||
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
|
||||
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue