ZRef

sealed abstract class ZRef[+EA, +EB, -A, +B] extends Serializable

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. set takes a value of type A and 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 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 ZRef provides the functional equivalent of a mutable reference, the value inside the ZRef should be immutable. For performance reasons ZRef 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
class Object
trait Matchable
class Any
ZRef[EA, EB, A, B]

Value members

Abstract methods

def fold[EC, ED, C, D](ea: EA => EC, eb: EB => ED, ca: C => Either[EC, A], bd: B => Either[ED, D]): ZRef[EC, ED, C, D]

Folds over the error and value types of the ZRef. This is a highly polymorphic method that is capable of arbitrarily transforming the error and value types of the ZRef. 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 ZRef. This is a highly polymorphic method that is capable of arbitrarily transforming the error and value types of the ZRef. 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.

def foldAll[EC, ED, C, D](ea: EA => EC, eb: EB => ED, ec: EB => EC, ca: C => B => Either[EC, A], bd: B => Either[ED, D]): ZRef[EC, ED, C, D]

Folds over the error and value types of the ZRef, 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 ZRef, allowing access to the state in transforming the set value. This is a more powerful version of fold but requires unifying the error types.

def get: IO[EB, B]

Reads the value from the ZRef.

Reads the value from the ZRef.

def set(a: A): IO[EA, Unit]

Writes a new value to the ZRef, with a guarantee of immediate consistency (at some cost to performance).

Writes a new value to the ZRef, with a guarantee of immediate consistency (at some cost to performance).

def setAsync(a: A): IO[EA, Unit]

Writes a new value to the ZRef without providing a guarantee of immediate consistency.

Writes a new value to the ZRef without providing a guarantee of immediate consistency.

Concrete methods

final def collect[C](pf: PartialFunction[B, C]): ZRef[EA, Option[EB], A, C]

Maps and filters the get value of the ZRef with the specified partial function, returning a ZRef 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 ZRef with the specified partial function, returning a ZRef with a get value that succeeds with the result of the partial function if it is defined or else fails with None.

final def contramap[C](f: C => A): ZRef[EA, EB, C, B]

Transforms the set value of the ZRef with the specified function.

Transforms the set value of the ZRef with the specified function.

final def contramapEither[EC >: EA, C](f: C => Either[EC, A]): ZRef[EC, EB, C, B]

Transforms the set value of the ZRef with the specified fallible function.

Transforms the set value of the ZRef with the specified fallible function.

final def dimap[C, D](f: C => A, g: B => D): ZRef[EA, EB, C, D]

Transforms both the set and get values of the ZRef with the specified functions.

Transforms both the set and get values of the ZRef with the specified functions.

final def dimapEither[EC >: EA, ED >: EB, C, D](f: C => Either[EC, A], g: B => Either[ED, D]): ZRef[EC, ED, C, D]

Transforms both the set and get values of the ZRef with the specified fallible functions.

Transforms both the set and get values of the ZRef with the specified fallible functions.

final def dimapError[EC, ED](f: EA => EC, g: EB => ED): ZRef[EC, ED, A, B]

Transforms both the set and get errors of the ZRef with the specified functions.

Transforms both the set and get errors of the ZRef with the specified functions.

final def filterInput[A1 <: A](f: A1 => Boolean): ZRef[Option[EA], EB, A1, B]

Filters the set value of the ZRef with the specified predicate, returning a ZRef with a set value that succeeds if the predicate is satisfied or else fails with None.

Filters the set value of the ZRef with the specified predicate, returning a ZRef with a set value that succeeds if the predicate is satisfied or else fails with None.

final def filterOutput(f: B => Boolean): ZRef[EA, Option[EB], A, B]

Filters the get value of the ZRef with the specified predicate, returning a ZRef with a get value that succeeds if the predicate is satisfied or else fails with None.

Filters the get value of the ZRef with the specified predicate, returning a ZRef with a get value that succeeds if the predicate is satisfied or else fails with None.

final def map[C](f: B => C): ZRef[EA, EB, A, C]

Transforms the get value of the ZRef with the specified function.

Transforms the get value of the ZRef with the specified function.

final def mapEither[EC >: EB, C](f: B => Either[EC, C]): ZRef[EA, EC, A, C]

Transforms the get value of the ZRef with the specified fallible function.

Transforms the get value of the ZRef with the specified fallible function.

final def readOnly: ZRef[EA, EB, Nothing, B]

Returns a read only view of the ZRef.

Returns a read only view of the ZRef.

final def writeOnly: ZRef[EA, Unit, A, Nothing]

Returns a write only view of the ZRef.

Returns a write only view of the ZRef.