mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 19:25:30 -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 empty = fun k -> ()
|
||||||
|
|
||||||
let singleton x k = k x
|
let singleton x k = k x
|
||||||
|
|
||||||
let return x k = k x
|
let return x k = k x
|
||||||
|
let pure f k = k f
|
||||||
|
|
||||||
(** Infinite sequence of the same element *)
|
(** Infinite sequence of the same element *)
|
||||||
let repeat x = fun k -> while true do k x done
|
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 = flat_map f x
|
||||||
|
|
||||||
let (>|=) x f = 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
|
end
|
||||||
|
|
||||||
include Infix
|
include Infix
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ val singleton : 'a -> 'a t
|
||||||
val return : 'a -> 'a t
|
val return : 'a -> 'a t
|
||||||
(** Synonym to {!singleton} *)
|
(** Synonym to {!singleton} *)
|
||||||
|
|
||||||
|
val pure : 'a -> 'a t
|
||||||
|
(** Synonym to {!singleton} *)
|
||||||
|
|
||||||
val repeat : 'a -> 'a t
|
val repeat : 'a -> 'a t
|
||||||
(** Infinite sequence of the same element. You may want to look
|
(** Infinite sequence of the same element. You may want to look
|
||||||
at {!take} if you iterate on it. *)
|
at {!take} if you iterate on it. *)
|
||||||
|
|
@ -442,6 +445,12 @@ module Infix : sig
|
||||||
|
|
||||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||||
(** Infix version of {!map} *)
|
(** 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
|
end
|
||||||
|
|
||||||
include module type of Infix
|
include module type of Infix
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue