Ref
class Ref<T> Import
Source: use cell::{Ref}; src/cell.hy A shared, mutable box holding one T.
Captured locals are copies: a lambda, defer block or task that assigns to a
captured variable changes only its own copy. Capture a Ref instead, and
every holder sees each set.
Associated functions#
| Name | Description |
|---|---|
new | New cell holding value. |
Methods#
| Name | Description |
|---|---|
get | Current value. |
set | Store value. |
replace | Store value and return the previous one. |
update | Store f(current) and return the new value. |
Examples#
use cell::{Ref};
use tests::assert;
let count = Ref::new(0);
let bump = fn () use (count) => count.update(fn (int n) => n + 1);
bump();
bump();
assert!(count.get() == 2);