diff --git a/sequence.ml b/sequence.ml index 549d1e2..cf7d1a5 100644 --- a/sequence.ml +++ b/sequence.ml @@ -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 -> diff --git a/sequence.mli b/sequence.mli index 16df438..c6602b0 100644 --- a/sequence.mli +++ b/sequence.mli @@ -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 *)