Skip to content

Commit

Permalink
Add Lwd.map_and_set
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole authored and let-def committed Dec 16, 2023
1 parent 1ed497d commit 1517853
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/lwd/lwd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ let peek = function
| Operator ({desc = Var v; _}) -> v.binding
| _ -> assert false

let map_and_set f v = set v (f (peek v))

(* Primitives *)
type 'a prim = 'a t
let prim ~acquire ~release =
Expand Down
3 changes: 3 additions & 0 deletions lib/lwd/lwd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ val peek : 'a var -> 'a
(** Observe the current value of the variable, without any dependency
tracking. *)

val map_and_set : ('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.
Expand Down

0 comments on commit 1517853

Please sign in to comment.