From 92205b6c36d55ba7f84471eddf7155b831614551 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 14 Sep 2017 09:12:34 +0200 Subject: [PATCH] add `Sequence.pair_with_idx` --- src/Sequence.ml | 4 ++++ src/Sequence.mli | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Sequence.ml b/src/Sequence.ml index 5ecfd23..a9c0f96 100644 --- a/src/Sequence.ml +++ b/src/Sequence.ml @@ -971,6 +971,10 @@ let of_list l k = List.iter k l let on_list f l = to_list (f (of_list l)) +let pair_with_idx seq k = + let r = ref 0 in + seq (fun x -> let n = !r in incr r; k (n,x)) + let to_opt = head let of_opt o k = match o with diff --git a/src/Sequence.mli b/src/Sequence.mli index d3effc8..2d686da 100644 --- a/src/Sequence.mli +++ b/src/Sequence.mli @@ -495,6 +495,10 @@ val on_list : ('a t -> 'b t) -> 'a list -> 'b list @since 0.5.2 *) +val pair_with_idx : 'a t -> (int * 'a) t +(** Similar to {!zip_i} but returns a normal sequence of tuples + @since NEXT_RELEASE *) + val to_opt : 'a t -> 'a option (** Alias to {!head} @since 0.5.1 *)