diff options
author | Sima Kinsart <hirrolot@gmail.com> | 2023-01-13 15:11:29 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 10:11:29 +0100 |
commit | e7c6254ad9bba467744da24c9502b48d9595daf8 (patch) | |
tree | cea571b299b0e2a7ea043f5a0d468f5c61b43f10 /stdlib/listLabels.mli | |
parent | c71cea8446ddd0360fa9aea436e43a736dfdfcc2 (diff) | |
download | ocaml-e7c6254ad9bba467744da24c9502b48d9595daf8.tar.gz |
Add `find_mapi` and `find_index` to `List`, `Seq`, `Array` and `Float.Array`. (#11848)
Diffstat (limited to 'stdlib/listLabels.mli')
-rw-r--r-- | stdlib/listLabels.mli | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/stdlib/listLabels.mli b/stdlib/listLabels.mli index 6acc7edbdd..7cab84c498 100644 --- a/stdlib/listLabels.mli +++ b/stdlib/listLabels.mli @@ -320,6 +320,14 @@ val find_opt : f:('a -> bool) -> 'a list -> 'a option @since 4.05 *) +val find_index : f:('a -> bool) -> 'a list -> int option +(** [find_index ~f xs] returns [Some i], where [i] is the index of the first + element of the list [xs] that satisfies [f x], if there is such an element. + + It returns [None] if there is no such element. + + @since 5.1 *) + val find_map : f:('a -> 'b option) -> 'a list -> 'b option (** [find_map ~f l] applies [f] to the elements of [l] in order, and returns the first result of the form [Some v], or [None] @@ -327,6 +335,13 @@ val find_map : f:('a -> 'b option) -> 'a list -> 'b option @since 4.10 *) +val find_mapi : f:(int -> 'a -> 'b option) -> 'a list -> 'b option +(** Same as [find_map], but the predicate is applied to the index of + the element as first argument (counting from 0), and the element + itself as second argument. + + @since 5.1 *) + val filter : f:('a -> bool) -> 'a list -> 'a list (** [filter ~f l] returns all the elements of the list [l] that satisfy the predicate [f]. The order of the elements |