mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
applicative and choice infix operators
This commit is contained in:
parent
20f70e721f
commit
abe4ba2aaf
2 changed files with 15 additions and 1 deletions
|
|
@ -49,8 +49,8 @@ let from_fun f =
|
|||
let empty = fun k -> ()
|
||||
|
||||
let singleton x k = k x
|
||||
|
||||
let return x k = k x
|
||||
let pure f k = k f
|
||||
|
||||
(** Infinite sequence of the same element *)
|
||||
let repeat x = fun k -> while true do k x done
|
||||
|
|
@ -701,6 +701,11 @@ module Infix = struct
|
|||
let (>>=) x f = flat_map f x
|
||||
|
||||
let (>|=) x f = map f x
|
||||
|
||||
let (<*>) funs args k =
|
||||
funs (fun f -> args (fun x -> k (f x)))
|
||||
|
||||
let (<+>) = append
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ val singleton : 'a -> 'a t
|
|||
val return : 'a -> 'a t
|
||||
(** Synonym to {!singleton} *)
|
||||
|
||||
val pure : '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. *)
|
||||
|
|
@ -442,6 +445,12 @@ module Infix : sig
|
|||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of {!map} *)
|
||||
|
||||
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
|
||||
(** Applicative operator (product+application) *)
|
||||
|
||||
val (<+>) : 'a t -> 'a t -> 'a t
|
||||
(** Concatenation of sequences *)
|
||||
end
|
||||
|
||||
include module type of Infix
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue