Class in cell coil-stdlib

Ref

class Ref<T>
Import
use cell::{Ref};
Source: 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#

NameDescription
newNew cell holding value.

Methods#

NameDescription
getCurrent value.
setStore value.
replaceStore value and return the previous one.
updateStore 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);

See also#

↑ ↓ navigate ↵ open