mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 03:05:29 -05:00
fmap function
This commit is contained in:
parent
4f06874e39
commit
12c0c5a6f5
2 changed files with 10 additions and 0 deletions
|
|
@ -129,6 +129,13 @@ let flatMap f seq =
|
||||||
from_iter
|
from_iter
|
||||||
(fun k -> seq (fun x -> (f x) k))
|
(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 *)
|
(** Insert the given element between every element of the sequence *)
|
||||||
let intersperse elem seq =
|
let intersperse elem seq =
|
||||||
fun k ->
|
fun k ->
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,9 @@ val flatMap : ('a -> 'b t) -> 'a t -> 'b t
|
||||||
(** Monadic bind. It applies the function to every element of the
|
(** Monadic bind. It applies the function to every element of the
|
||||||
initial sequence, and calls [concat]. *)
|
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
|
val intersperse : 'a -> 'a t -> 'a t
|
||||||
(** Insert the second element between every element of the sequence *)
|
(** Insert the second element between every element of the sequence *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue