mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
add monadic operators and >|=
This commit is contained in:
parent
a40866e9ec
commit
ed5a602f4e
2 changed files with 17 additions and 1 deletions
|
|
@ -48,7 +48,9 @@ let from_fun f =
|
|||
|
||||
let empty = fun k -> ()
|
||||
|
||||
let singleton x = fun k -> k x
|
||||
let singleton x k = k x
|
||||
|
||||
let return x k = k x
|
||||
|
||||
(** Infinite sequence of the same element *)
|
||||
let repeat x = fun k -> while true do k x done
|
||||
|
|
@ -695,6 +697,10 @@ module Infix = struct
|
|||
let (--) i j = int_range ~start:i ~stop:j
|
||||
|
||||
let (--^) i j = int_range_dec ~start:i ~stop:j
|
||||
|
||||
let (>>=) x f = flat_map f x
|
||||
|
||||
let (>|=) x f = map f x
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
|
|
|||
10
sequence.mli
10
sequence.mli
|
|
@ -76,6 +76,9 @@ val empty : 'a t
|
|||
val singleton : 'a -> 'a t
|
||||
(** Singleton sequence, with exactly one element. *)
|
||||
|
||||
val return : 'a -> 'a t
|
||||
(** Synonym to {!singleton} *)
|
||||
|
||||
val repeat : 'a -> 'a t
|
||||
(** Infinite sequence of the same element. You may want to look
|
||||
at {!take} if you iterate on it. *)
|
||||
|
|
@ -433,10 +436,17 @@ module Infix : sig
|
|||
(** [a --^ b] is the range of integers from [b] to [a], both included,
|
||||
in decreasing order (starts from [a]).
|
||||
It will therefore be empty if [a < b]. *)
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** Monadic bind (infix version of {!flat_map} *)
|
||||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of {!map} *)
|
||||
end
|
||||
|
||||
include module type of Infix
|
||||
|
||||
|
||||
(** {2 Pretty printing of sequences} *)
|
||||
|
||||
val pp_seq : ?sep:string -> (Format.formatter -> 'a -> unit) ->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue