mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
a few more combinators for Behavior
This commit is contained in:
parent
fa40412216
commit
a45fccca98
2 changed files with 17 additions and 2 deletions
10
behavior.ml
10
behavior.ml
|
|
@ -77,9 +77,9 @@ let test_signal s = TestFun (fun () -> React.S.value s)
|
|||
|
||||
let wait e = Wait e
|
||||
|
||||
let timeout f = Sequence (false, [Timeout f; Fail])
|
||||
let timeout f = Sequence (false, [Timeout f; fail])
|
||||
|
||||
let delay f = Sequence (false, [Timeout f; Succeed])
|
||||
let delay f = Sequence (false, [Timeout f; succeed])
|
||||
|
||||
let do_ act = Do act
|
||||
|
||||
|
|
@ -87,10 +87,16 @@ let do_succeed act = Do (fun () -> act (); true)
|
|||
|
||||
let if_ s then_ else_ = If (s, then_, else_)
|
||||
|
||||
let when_ s t = if_ s t succeed
|
||||
|
||||
let while_ s l = Sequence (true, (test_signal s) :: l)
|
||||
|
||||
let sequence ?(loop=false) l =
|
||||
assert (l <> []);
|
||||
Sequence (loop, l)
|
||||
|
||||
let repeat t = sequence ~loop:true [t]
|
||||
|
||||
let select ?(strat=strategy_inorder) l =
|
||||
assert (l <> []);
|
||||
Select (strat, l)
|
||||
|
|
|
|||
|
|
@ -109,9 +109,18 @@ val do_succeed : (unit -> unit) -> tree
|
|||
val if_ : bool React.signal -> tree -> tree -> tree
|
||||
(** Conditional choice, based on the current value of the signal *)
|
||||
|
||||
val when_ : bool React.signal -> tree -> tree
|
||||
(** Run the given tree if the signal is true, else succeed *)
|
||||
|
||||
val while_ : bool React.signal -> tree list -> tree
|
||||
(** While the signal is true, run the subtrees *)
|
||||
|
||||
val sequence : ?loop:bool -> tree list -> tree
|
||||
(** Sequence of sub-trees to run *)
|
||||
|
||||
val repeat : tree -> tree
|
||||
(** Repeat the same tree indefinitely *)
|
||||
|
||||
val select : ?strat:select_strategy -> tree list -> tree
|
||||
(** Choice among the subtrees. The strategy defines in which order subtrees
|
||||
are tried. *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue