Imandrakit_thread.Rvar
Reactive variable.
A reactive variable holds state, and can change state over time. One can subscribe to changes or just get the current value.
val return : 'a -> 'a t
A frozen variable with the given content.
val get : 'a t -> 'a
Get the current value.
val pp : 'a Imandrakit.Fmt.printer -> 'a t Imandrakit.Fmt.printer
val mk_var : 'a -> 'a t
Make a new variable with the given initial value
val set : 'a t -> 'a -> unit
Set the value. This will trigger all the callbacks registered via on_change
.
val update : 'a t -> f:('a -> 'a * 'b) -> 'b
Modifies content and return side value.
val freeze : _ t -> unit
Prevent further mutations. Idempotent.
on_change rv f
subscribes f
to be called whenever rv
changes. When rv
is set to a new value x
, f (Some x)
is called. When rv
is frozen, f None
is called (and then f
will never be called again).
If rv
is already frozen then f None
will be called immediately.
val of_fut_or_error : 'a Fut.t -> 'a Fut.or_error option t
Pick a value from a list of variables. The result is a variable that is always as up-to-date as any of the inputs.
cutoff v
produces a new variable that always has the same value as v
, but only emits "on change" events when the new value differs from the old one.
module Monoid : sig ... end
monoid_merge m ~f v1 v2
maps each variable using f
and then merges the results using the given monoid.
monoid_merge m ~f rvs
maps each variable using f
and then merges the results using the given monoid.
module Infix : sig ... end