diff --git a/lib/lwd/lwd.ml b/lib/lwd/lwd.ml index 3c77a27..4fb8ad5 100644 --- a/lib/lwd/lwd.ml +++ b/lib/lwd/lwd.ml @@ -308,6 +308,8 @@ let peek = function | Operator ({desc = Var v; _}) -> v.binding | _ -> assert false +let update f v = set v (f (peek v)) + (* Primitives *) type 'a prim = 'a t let prim ~acquire ~release = diff --git a/lib/lwd/lwd.mli b/lib/lwd/lwd.mli index 386dde3..e42389f 100644 --- a/lib/lwd/lwd.mli +++ b/lib/lwd/lwd.mli @@ -67,6 +67,9 @@ val peek : 'a var -> 'a (** Observe the current value of the variable, without any dependency tracking. *) +val update : ('a -> 'a) -> 'a var -> unit +(** Modify a variable based on its currently observed value. *) + type +'a prim (** A primitive document. It can correspond, for example, to a primitive UI element.