IORef<T> class final

Mutable reference in the IO monad.

Allows having a reference that can be read and mutated inside the IO monad. Can be used in conjunction with a closure to preserve a state across multiple IO function calls, or in any other case where code is run inside an IO monad.

In most cases, the State monad should be used, and IORef must be viewed as a last resort, as it holds a mutable field inside itself that can be modified inside of the IO monad.


hashCode int
The hash code for this object.
runtimeType Type
A representation of the runtime type of the object.


modify(Endo<T> update) IO<Unit>
Works almost identical to the write method, but instead of taking a value that needs to be written, takes an Endo function, applies the IORef's current value to it and writes the result to the IORef.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
read() IO<T>
Extracts a current value of the IORef and returns it inside the IO monad.
toString() String
A string representation of this object.
write(T value) IO<Unit>
Writes the given value to the IORef and returns a Unit inside the IO monad.


operator ==(Object other) bool
The equality operator.

Static Methods

create<T>(T initial) IO<IORef<T>>
Creates a new IORef inside an IO monad with a given initial value.