mirror of
https://github.com/c-cube/iter.git
synced 2025-12-05 19:00:31 -05:00
add Sequence.filter_mapi
This commit is contained in:
parent
dee62387aa
commit
d59d96a513
3 changed files with 18 additions and 2 deletions
|
|
@ -197,8 +197,16 @@ let seq_list l = seq_list_map (fun x->x) l
|
|||
let filter_map f seq k =
|
||||
seq (fun x -> match f x with
|
||||
| None -> ()
|
||||
| Some y -> k y
|
||||
)
|
||||
| Some y -> k y)
|
||||
|
||||
let filter_mapi f seq k =
|
||||
let i = ref 0 in
|
||||
seq (fun x ->
|
||||
let j = !i in
|
||||
incr i;
|
||||
match f j x with
|
||||
| None -> ()
|
||||
| Some y -> k y)
|
||||
|
||||
let intersperse elem seq k =
|
||||
let first = ref true in
|
||||
|
|
|
|||
|
|
@ -215,6 +215,10 @@ val filter_map : ('a -> 'b option) -> 'a t -> 'b t
|
|||
Formerly [fmap]
|
||||
@since 0.5 *)
|
||||
|
||||
val filter_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b t
|
||||
(** Map with indices, and only keep non-[None] elements
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val intersperse : 'a -> 'a t -> 'a t
|
||||
(** Insert the single element between every element of the sequence *)
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,10 @@ val flat_map_l : f:('a -> 'b list) -> 'a t -> 'b t
|
|||
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t
|
||||
(** Alias to {!fmap} with a more explicit name *)
|
||||
|
||||
val filter_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b t
|
||||
(** Map with indices, and only keep non-[None] elements
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val seq_list : 'a t list -> 'a list t
|
||||
(** [seq_list l] returns all the ways to pick one element in each sub-sequence
|
||||
in [l]. Assumes the sub-sequences can be iterated on several times.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue