sealed abstract class ZRef[-RA, -RB, +EA, +EB, -A, +B] extends Serializable
A ZRef[RA, RB, 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, requiring an environment of type RA and potentially
failing with an error of type EA. get gets the current value of the
reference and returns a value of type B, requiring an environment of type
RB and 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[R, R, E, E, A, A], the ZRef also supports atomic modify and
update operations. All operations are guaranteed to be safe for concurrent
access.
By default, ZRef is implemented in terms of compare and swap operations
for maximum performance and does not support performing effects within
update operations. If you need to perform effects within update operations
you can create a ZRef.Synchronized, a specialized type of ZRef that
supports performing effects within update operations at some cost to
performance. In this case writes will semantically block other writers,
while multiple readers can read simultaneously.
ZRef.Synchronized also supports composing multiple ZRef.Synchronized
values together to form a single ZRef.Synchronized value that can be
atomically updated using the zip operator. In this case reads and writes
will semantically block other readers and writers.
NOTE: While ZRef provides the functional equivalent of a mutable
reference, the value inside the ZRef should normally be immutable since
compare and swap operations are not safe for mutable values that do not
support concurrent access. If you do need to use a mutable value
ZRef.Synchronized will guarantee that access to the value is properly
synchronized.
- Self Type
- ZRef[RA, RB, EA, EB, A, B]
- Alphabetic
- By Inheritance
- ZRef
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def fold[EC, ED, C, D](ea: (EA) => EC, eb: (EB) => ED, ca: (C) => Either[EC, A], bd: (B) => Either[ED, D]): ZRef[RA, RB, EC, ED, C, D]
Folds over the error and value types of the
ZRef.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 theZRef. For most use cases one of the more specific combinators implemented in terms offoldwill be more ergonomic but this method is extremely useful for implementing new combinators. - abstract 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[RA with RB, RB, EC, ED, C, D]
Folds over the error and value types of the
ZRef, allowing access to the state in transforming thesetvalue.Folds over the error and value types of the
ZRef, allowing access to the state in transforming thesetvalue. This is a more powerful version offoldbut requires unifying the error types. - abstract def get: ZIO[RB, EB, B]
Reads the value from the
ZRef. - abstract def set(a: A): ZIO[RA, EA, Unit]
Writes a new value to the
ZRef, with a guarantee of immediate consistency (at some cost to performance). - abstract def setAsync(a: A): ZIO[RA, EA, Unit]
Writes a new value to the
ZRefwithout providing a guarantee of immediate consistency.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[C](pf: PartialFunction[B, C]): ZRef[RA, RB, EA, Option[EB], A, C]
Maps and filters the
getvalue of theZRefwith the specified partial function, returning aZRefwith agetvalue that succeeds with the result of the partial function if it is defined or else fails withNone. - def contramap[C](f: (C) => A): ZRef[RA, RB, EA, EB, C, B]
Transforms the
setvalue of theZRefwith the specified function. - def contramapEither[EC >: EA, C](f: (C) => Either[EC, A]): ZRef[RA, RB, EC, EB, C, B]
Transforms the
setvalue of theZRefwith the specified fallible function. - def dimap[C, D](f: (C) => A, g: (B) => D): ZRef[RA, RB, EA, EB, C, D]
Transforms both the
setandgetvalues of theZRefwith the specified functions. - def dimapEither[EC >: EA, ED >: EB, C, D](f: (C) => Either[EC, A], g: (B) => Either[ED, D]): ZRef[RA, RB, EC, ED, C, D]
Transforms both the
setandgetvalues of theZRefwith the specified fallible functions. - def dimapError[EC, ED](f: (EA) => EC, g: (EB) => ED): ZRef[RA, RB, EC, ED, A, B]
Transforms both the
setandgeterrors of theZRefwith the specified functions. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def filterInput[A1 <: A](f: (A1) => Boolean): ZRef[RA, RB, Option[EA], EB, A1, B]
Filters the
setvalue of theZRefwith the specified predicate, returning aZRefwith asetvalue that succeeds if the predicate is satisfied or else fails withNone. - def filterOutput(f: (B) => Boolean): ZRef[RA, RB, EA, Option[EB], A, B]
Filters the
getvalue of theZRefwith the specified predicate, returning aZRefwith agetvalue that succeeds if the predicate is satisfied or else fails withNone. - def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[C](f: (B) => C): ZRef[RA, RB, EA, EB, A, C]
Transforms the
getvalue of theZRefwith the specified function. - def mapEither[EC >: EB, C](f: (B) => Either[EC, C]): ZRef[RA, RB, EA, EC, A, C]
Transforms the
getvalue of theZRefwith the specified fallible function. - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def readOnly: ZRef[RA, RB, EA, EB, Nothing, B]
Returns a read only view of the
ZRef. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def writeOnly: ZRef[RA, RB, EA, Unit, A, Nothing]
Returns a write only view of the
ZRef.