add Sequence.pair_with_idx

This commit is contained in:
Simon Cruanes 2017-09-14 09:12:34 +02:00
parent 11529ea6ff
commit 92205b6c36
2 changed files with 8 additions and 0 deletions

View file

@ -971,6 +971,10 @@ let of_list l k = List.iter k l
let on_list f l = let on_list f l =
to_list (f (of_list 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 to_opt = head
let of_opt o k = match o with let of_opt o k = match o with

View file

@ -495,6 +495,10 @@ val on_list : ('a t -> 'b t) -> 'a list -> 'b list
@since 0.5.2 @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 val to_opt : 'a t -> 'a option
(** Alias to {!head} (** Alias to {!head}
@since 0.5.1 *) @since 0.5.1 *)