A ZTRef[EA, EB, A, B]
is a polymorphic, purely functional description of a
mutable reference that can be modified as part of a transactional effect. The
fundamental operations of a ZTRef
are set
and get
. set
takes a value
of type A
and transactionally sets the reference to a new value,
potentially failing with an error of type EA
. get
gets the current value
of the reference and returns a value of type B
, potentially failing with an
error of type EB
.
When the error and value types of the ZTRef
are unified, that is, it is a
ZTRef[E, E, A, A]
, the ZTRef
also supports atomic modify
and update
operations. All operations are guaranteed to be executed transactionally.
NOTE: While ZTRef
provides the transactional equivalent of a mutable
reference, the value inside the ZTRef
should be immutable. For performance
reasons ZTRef
is 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.
- Companion:
- object
Value members
Abstract methods
Folds over the error and value types of the ZTRef
. This is a highly
polymorphic method that is capable of arbitrarily transforming the error
and value types of the ZTRef
. For most use cases one of the more specific
combinators implemented in terms of fold
will be more ergonomic but this
method is extremely useful for implementing new combinators.
Folds over the error and value types of the ZTRef
. This is a highly
polymorphic method that is capable of arbitrarily transforming the error
and value types of the ZTRef
. For most use cases one of the more specific
combinators implemented in terms of fold
will be more ergonomic but this
method is extremely useful for implementing new combinators.
Folds over the error and value types of the ZTRef
, allowing access to the
state in transforming the set
value. This is a more powerful version of
fold
but requires unifying the error types.
Folds over the error and value types of the ZTRef
, allowing access to the
state in transforming the set
value. This is a more powerful version of
fold
but requires unifying the error types.
Concrete methods
Maps and filters the get
value of the ZTRef
with the specified partial
function, returning a ZTRef
with a get
value that succeeds with the
result of the partial function if it is defined or else fails with None
.
Maps and filters the get
value of the ZTRef
with the specified partial
function, returning a ZTRef
with a get
value that succeeds with the
result of the partial function if it is defined or else fails with None
.
Transforms the set
value of the ZTRef
with the specified function.
Transforms the set
value of the ZTRef
with the specified function.
Transforms the set
value of the ZTRef
with the specified fallible
function.
Transforms the set
value of the ZTRef
with the specified fallible
function.
Transforms both the set
and get
values of the ZTRef
with the
specified functions.
Transforms both the set
and get
values of the ZTRef
with the
specified functions.
Transforms both the set
and get
values of the ZTRef
with the
specified fallible functions.
Transforms both the set
and get
values of the ZTRef
with the
specified fallible functions.
Transforms both the set
and get
errors of the ZTRef
with the
specified functions.
Transforms both the set
and get
errors of the ZTRef
with the
specified functions.
Filters the set
value of the ZTRef
with the specified predicate,
returning a ZTRef
with a set
value that succeeds if the predicate is
satisfied or else fails with None
.
Filters the set
value of the ZTRef
with the specified predicate,
returning a ZTRef
with a set
value that succeeds if the predicate is
satisfied or else fails with None
.
Filters the get
value of the ZTRef
with the specified predicate,
returning a ZTRef
with a get
value that succeeds if the predicate is
satisfied or else fails with None
.
Filters the get
value of the ZTRef
with the specified predicate,
returning a ZTRef
with a get
value that succeeds if the predicate is
satisfied or else fails with None
.
Folds over the error and value types of the ZTRef
, allowing access to the
state in transforming the set
value. This is a more powerful version of
fold
but requires unifying the error types.
Folds over the error and value types of the ZTRef
, allowing access to the
state in transforming the set
value. This is a more powerful version of
fold
but requires unifying the error types.
Folds over the error and value types of the ZTRef
. This is a highly
polymorphic method that is capable of arbitrarily transforming the error
and value types of the ZTRef
. For most use cases one of the more specific
combinators implemented in terms of fold
will be more ergonomic but this
method is extremely useful for implementing new combinators.
Folds over the error and value types of the ZTRef
. This is a highly
polymorphic method that is capable of arbitrarily transforming the error
and value types of the ZTRef
. For most use cases one of the more specific
combinators implemented in terms of fold
will be more ergonomic but this
method is extremely useful for implementing new combinators.
Transforms the get
value of the ZTRef
with the specified function.
Transforms the get
value of the ZTRef
with the specified function.
Transforms the get
value of the ZTRef
with the specified fallible
function.
Transforms the get
value of the ZTRef
with the specified fallible
function.