Class/Object

zio

ZRef

Related Docs: object ZRef | package zio

Permalink

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]
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ZRef
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. 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]

    Permalink

    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 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.

  2. 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]

    Permalink

    Folds over the error and value types of the ZRef, allowing access to the state in transforming the set value.

    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.

  3. abstract def get(implicit trace: ZTraceElement): ZIO[RB, EB, B]

    Permalink

    Reads the value from the ZRef.

  4. abstract def set(a: A)(implicit trace: ZTraceElement): ZIO[RA, EA, Unit]

    Permalink

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

  5. abstract def setAsync(a: A)(implicit trace: ZTraceElement): ZIO[RA, EA, Unit]

    Permalink

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

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def collect[C](pf: PartialFunction[B, C]): ZRef[RA, RB, EA, Option[EB], A, C]

    Permalink

    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.

  7. def contramap[C](f: (C) ⇒ A): ZRef[RA, RB, EA, EB, C, B]

    Permalink

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

  8. def contramapEither[EC >: EA, C](f: (C) ⇒ Either[EC, A]): ZRef[RA, RB, EC, EB, C, B]

    Permalink

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

  9. def dimap[C, D](f: (C) ⇒ A, g: (B) ⇒ D): ZRef[RA, RB, EA, EB, C, D]

    Permalink

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

  10. 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]

    Permalink

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

  11. def dimapError[EC, ED](f: (EA) ⇒ EC, g: (EB) ⇒ ED): ZRef[RA, RB, EC, ED, A, B]

    Permalink

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

  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  14. def filterInput[A1 <: A](f: (A1) ⇒ Boolean): ZRef[RA, RB, Option[EA], EB, A1, B]

    Permalink

    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.

  15. def filterOutput(f: (B) ⇒ Boolean): ZRef[RA, RB, EA, Option[EB], A, B]

    Permalink

    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.

  16. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  20. def map[C](f: (B) ⇒ C): ZRef[RA, RB, EA, EB, A, C]

    Permalink

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

  21. def mapEither[EC >: EB, C](f: (B) ⇒ Either[EC, C]): ZRef[RA, RB, EA, EC, A, C]

    Permalink

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

  22. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  23. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. def readOnly: ZRef[RA, RB, EA, EB, Nothing, B]

    Permalink

    Returns a read only view of the ZRef.

  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  27. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  28. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. def writeOnly: ZRef[RA, RB, EA, Unit, A, Nothing]

    Permalink

    Returns a write only view of the ZRef.

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped