interior/cell
A Cell
is a mutable container.
It can be used to provide interior mutability, allowing for mutating state in an otherwise immutable object.
⚠️ Disclaimer
Types in Gleam are immutable for a reason! As such, you should use immutable data structures whenever possible.
Don’t use this library to shortcut structuring your code and APIs in a functional way that embraces immutability!
That being said, there are some scenarios where it can be handy to have shared mutable state, such as when implementing mock objects for testing.
Target implementation
On the Erlang target, each Cell
is backed by an actor.
On the JavaScript target, each Cell
is a mutable memory location.
Types
Values
pub fn set(cell: Cell(a), value: a) -> Nil
Sets the contained value of the cell to the given value.