mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
rename CCList.find -> CClist.find_map (same for findi), deprecate old name
This commit is contained in:
parent
2ae6dfd11c
commit
4b704d9d1a
2 changed files with 17 additions and 6 deletions
|
|
@ -401,7 +401,7 @@ let find_pred_exn p l = match find_pred p l with
|
|||
find_pred (fun x -> x < 10) (1 -- 9) = Some 1
|
||||
*)
|
||||
|
||||
let findi f l =
|
||||
let find_mapi f l =
|
||||
let rec aux f i = function
|
||||
| [] -> None
|
||||
| x::l' ->
|
||||
|
|
@ -410,9 +410,12 @@ let findi f l =
|
|||
| None -> aux f (i+1) l'
|
||||
in aux f 0 l
|
||||
|
||||
let find f l = findi (fun _ -> f) l
|
||||
let find_map f l = find_mapi (fun _ -> f) l
|
||||
|
||||
let find_idx p l = findi (fun i x -> if p x then Some (i, x) else None) l
|
||||
let find = find_map
|
||||
let findi = find_mapi
|
||||
|
||||
let find_idx p l = find_mapi (fun i x -> if p x then Some (i, x) else None) l
|
||||
|
||||
(*$T
|
||||
find (fun x -> if x=3 then Some "a" else None) [1;2;3;4] = Some "a"
|
||||
|
|
|
|||
|
|
@ -119,13 +119,21 @@ val find_pred_exn : ('a -> bool) -> 'a t -> 'a
|
|||
@raise Not_found if no such element is found
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val find : ('a -> 'b option) -> 'a t -> 'b option
|
||||
val find_map : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find f l] traverses [l], applying [f] to each element. If for
|
||||
some element [x], [f x = Some y], then [Some y] is returned. Otherwise
|
||||
the call returns [None] *)
|
||||
the call returns [None]
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val find : ('a -> 'b option) -> 'a list -> 'b option
|
||||
(** @deprecated in favor of {!find_map}, for the name is too confusing *)
|
||||
|
||||
val find_mapi : (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.
|
||||
(** @deprecated in favor of {!find_mapi}, name is too confusing
|
||||
@since 0.3.4 *)
|
||||
|
||||
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue