fmap function

This commit is contained in:
Simon Cruanes 2013-08-28 15:01:09 +02:00
parent 4f06874e39
commit 12c0c5a6f5
2 changed files with 10 additions and 0 deletions

View file

@ -129,6 +129,13 @@ let flatMap f seq =
from_iter
(fun k -> seq (fun x -> (f x) k))
let fmap f seq =
from_iter
(fun k ->
seq (fun x -> match f x with
| None -> ()
| Some y -> k y))
(** Insert the given element between every element of the sequence *)
let intersperse elem seq =
fun k ->

View file

@ -125,6 +125,9 @@ 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 fmap : ('a -> 'b option) -> 'a t -> 'b t
(** Specialized version of {!flatMap} for options. *)
val intersperse : 'a -> 'a t -> 'a t
(** Insert the second element between every element of the sequence *)