diff --git a/src/Sequence.ml b/src/Sequence.ml index af6ff4e..485a7b2 100644 --- a/src/Sequence.ml +++ b/src/Sequence.ml @@ -699,7 +699,7 @@ let mem ?(eq=(=)) x seq = exists (eq x) seq exception ExitFind -let find f seq = +let find_map f seq = let r = ref None in begin try @@ -711,7 +711,9 @@ let find f seq = end; !r -let findi f seq = +let find = find_map + +let find_mapi f seq = let i = ref 0 in let r = ref None in begin @@ -724,7 +726,9 @@ let findi f seq = end; !r -let find_pred f seq = find (fun x -> if f x then Some x else None) seq +let findi = find_mapi + +let find_pred f seq = find_map (fun x -> if f x then Some x else None) seq let find_pred_exn f seq = match find_pred f seq with | Some x -> x diff --git a/src/Sequence.mli b/src/Sequence.mli index d52cdac..15d394a 100644 --- a/src/Sequence.mli +++ b/src/Sequence.mli @@ -144,10 +144,18 @@ val find : ('a -> 'b option) -> 'a t -> 'b option (** Find the first element on which the function doesn't return [None] @since 0.5 *) +val find_map : ('a -> 'b option) -> 'a t -> 'b option +(** Alias to {!find} + @since NEXT_RELEASE *) + val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option (** Indexed version of {!find} @since 0.9 *) +val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option +(** Alias to {!findi} + @since NEXT_RELEASE *) + val find_pred : ('a -> bool) -> 'a t -> 'a option (** [find_pred p l] finds the first element of [l] that satisfies [p], or returns [None] if no element satisfies [p]