mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 03:05:29 -05:00
added flatMap to the combinators
This commit is contained in:
parent
55ff51f2cb
commit
8c44f7c63e
2 changed files with 12 additions and 2 deletions
10
sequence.ml
10
sequence.ml
|
|
@ -99,10 +99,16 @@ let append s1 s2 =
|
|||
|
||||
(** Concatenate a sequence of sequences into one sequence *)
|
||||
let concat s =
|
||||
fun k ->
|
||||
from_iter (fun k ->
|
||||
(* function that is called on every sub-sequence *)
|
||||
let k_seq seq = iter k seq in
|
||||
s k_seq
|
||||
s k_seq)
|
||||
|
||||
(** Monadic bind. It applies the function to every element of the
|
||||
initial sequence, and calls [concat]. *)
|
||||
let flatMap f seq =
|
||||
from_iter
|
||||
(fun k -> seq (fun x -> (f x) k))
|
||||
|
||||
exception ExitSequence
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,10 @@ val append : 'a t -> 'a t -> 'a t
|
|||
val concat : 'a t t -> 'a t
|
||||
(** Concatenate a sequence of sequences into one sequence *)
|
||||
|
||||
val flatMap : ('a -> 'b t) -> 'a t -> 'b t
|
||||
(** Monadic bind. It applies the function to every element of the
|
||||
initial sequence, and calls [concat]. *)
|
||||
|
||||
val take : int -> 'a t -> 'a t
|
||||
(** Take at most [n] elements from the sequence *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue