monadic map operator

This commit is contained in:
carm 2014-12-09 22:32:21 -05:00
parent d67dceddb8
commit 912c6859cd
3 changed files with 9 additions and 1 deletions

View file

@ -1362,6 +1362,7 @@ module Infix = struct
let (--) = int_range
let (>>=) x f = flat_map f x
let (>>|) x f = map f x
end
include Infix
@ -1543,6 +1544,7 @@ module Restart = struct
let (--) = int_range
let (>>=) x f = flat_map f x
let (>>|) x f = map f x
end
include Infix

View file

@ -306,6 +306,9 @@ module type S = sig
val (>>=) : 'a t -> ('a -> 'b gen) -> 'b t
(** Monadic bind operator *)
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
(** Monadic map operator *)
end
val (--) : int -> int -> int t
@ -314,6 +317,9 @@ module type S = sig
val (>>=) : 'a t -> ('a -> 'b gen) -> 'b t
(** Monadic bind operator *)
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
(** Monadic map operator *)
val pp : ?start:string -> ?stop:string -> ?sep:string -> ?horizontal:bool ->
(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
(** Pretty print the content of the generator on a formatter. *)

View file

@ -42,7 +42,7 @@ let test_iter () =
let test_map () =
let e = 1 -- 10 in
let e' = Gen.map string_of_int e in
let e' = e >>| string_of_int in
OUnit.assert_equal ~printer:pstrlist ["9"; "10"] (Gen.to_list (Gen.drop 8 e'));
()