mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
append/concat primitives
This commit is contained in:
parent
57b778f6cc
commit
7dbd8d15e3
2 changed files with 15 additions and 4 deletions
12
sequence.ml
12
sequence.ml
|
|
@ -30,11 +30,19 @@ let filter p seq =
|
||||||
let seq_fun' k = seq.seq_fun (fun x -> if p x then k x) in
|
let seq_fun' k = seq.seq_fun (fun x -> if p x then k x) in
|
||||||
{ seq_fun=seq_fun'; }
|
{ seq_fun=seq_fun'; }
|
||||||
|
|
||||||
(** Concatenate two sequences *)
|
(** Append two sequences *)
|
||||||
let concat s1 s2 =
|
let append s1 s2 =
|
||||||
let seq_fun k = s1.seq_fun k; s2.seq_fun k in
|
let seq_fun k = s1.seq_fun k; s2.seq_fun k in
|
||||||
{ seq_fun; }
|
{ seq_fun; }
|
||||||
|
|
||||||
|
(** Concatenate a sequence of sequences into one sequence *)
|
||||||
|
let concat s =
|
||||||
|
let seq_fun k =
|
||||||
|
(* function that is called on every sub-sequence *)
|
||||||
|
let k_seq seq = iter k seq in
|
||||||
|
s.seq_fun k_seq
|
||||||
|
in { seq_fun; }
|
||||||
|
|
||||||
(** Take at most [n] elements from the sequence *)
|
(** Take at most [n] elements from the sequence *)
|
||||||
let take n seq =
|
let take n seq =
|
||||||
let count = ref 0 in
|
let count = ref 0 in
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,11 @@ val map : ('a -> 'b) -> 'a t -> 'b t
|
||||||
val filter : ('a -> bool) -> 'a t -> 'a t
|
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||||
(** Filter on elements of the sequence *)
|
(** Filter on elements of the sequence *)
|
||||||
|
|
||||||
val concat : 'a t -> 'a t -> 'a t
|
val append : 'a t -> 'a t -> 'a t
|
||||||
(** Concatenate two sequences *)
|
(** Append two sequences *)
|
||||||
|
|
||||||
|
val concat : 'a t t -> 'a t
|
||||||
|
(** Concatenate a sequence of sequences into one sequence *)
|
||||||
|
|
||||||
val take : int -> 'a t -> 'a t
|
val take : int -> 'a t -> 'a t
|
||||||
(** Take at most [n] elements from the sequence *)
|
(** Take at most [n] elements from the sequence *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue