ZRef
A ZRef[EA, EB, A, B] is a polymorphic, purely functional description of a mutable reference. The fundamental operations of a ZRef are set and get.
settakes a value of typeAand sets the reference to a new value, potentially failing with an error of typeEA.getgets the current value of the reference and returns a value of typeB, potentially failing with an error of typeEB.
When the error and value types of the ZRef are unified, that is, it is a ZRef[E, E, A, A], the ZRef also supports atomic modify and update operations. All operations are guaranteed to be safe for concurrent access.
Note:
While
ZRefprovides the functional equivalent of a mutable reference, the value inside theZRefshould be immutable. For performance reasonsZRefis implemented in terms of compare and swap operations rather than synchronization. These operations are not safe for mutable values that do not support concurrent access.