ref

A ref cell library for the gleam erlang target. The implementation uses actors for keeping track of the values of references, so a new process is spawned for each mutable reference you create. These mutable references should only be used if mutability is absolutely required. Immutability should always be preferred, and this implementation loses the performance benefits that mutability generally provide.

Types

The reference cell type for holding mutable data

pub opaque type RefCell(a)

Functions

pub fn cell(contents: a) -> RefCell(a)

Public constructor for creating a new RefCell. The initial value is passed, and a RefCell containing that value is returned.

pub fn get(cell: RefCell(a)) -> a

Used for extracting the held data in a RefCell. Once the value has been extracted with this function, any mutations on the Cell will not affect the data already extracted.

pub fn main() -> Int
pub fn map(subj: RefCell(a), f: fn(a) -> b) -> RefCell(b)

Map the result of a function taking a Cell’s contents into a new RefCell. No mutation takes place

pub fn set(cell: RefCell(a), contents: a) -> Nil

Used for setting the inner value of a RefCell

pub fn set_fun(cell: RefCell(a), f: fn(a) -> a) -> RefCell(a)

Weird restrictive binding operation for a RefCell, as the operation sets the cell to the value that the passed function evaluates to

Search Document