let k1 : int key = newkey () in
let k2 : int key = newkey () in
let k3 : string key = newkey () in
let set =
empty
|> set ~key:k1 1
|> set ~key:k2 2
|> set ~key:k3 "3"
in
assert (get ~key:k1 set = Some 1);
assert (get ~key:k2 set = Some 2);
assert (get ~key:k3 set = Some "3");
()
val newkey : unit ‑> 'a key
newkey ()
creates a new unique key that can be used to access
a 'a
value in a set. Each key created with newkey
is distinct
from any other key, even if they have the same type.
Not thread-safe.
set ~key v set
maps key
to v
in set
. It means that
for every set
, get ~key (set ~key v set) = Some v
.
Same as get, but can fail.