Packages

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

A FiberRef is ZIO's equivalent of Java's ThreadLocal. The value of a FiberRef is automatically propagated to child fibers when they are forked and merged back in to the value of the parent fiber after they are joined.

for {
  fiberRef <- FiberRef.make("Hello world!")
  child    <- fiberRef.set("Hi!).fork
  result   <- child.join
} yield result

Here result will be equal to "Hi!" since changed made by a child fiber are merged back in to the value of the parent fiber on join.

By default the value of the child fiber will replace the value of the parent fiber on join but you can specify your own logic for how values should be merged.

for {
  fiberRef <- FiberRef.make(0, math.max)
  child    <- fiberRef.update(_ + 1).fork
  _        <- fiberRef.update(_ + 2)
  _        <- child.join
  value    <- fiberRef.get
} yield value

Here value will be 2 as the value in the joined fiber is lower and we specified max as our combining function.

Self Type
ZFiberRef[EA, EB, A, B]
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ZFiberRef
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

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]): ZFiberRef[EC, ED, C, D]

    Folds over the error and value types of the ZFiberRef.

    Folds over the error and value types of the ZFiberRef. This is a highly polymorphic method that is capable of arbitrarily transforming the error and value types of the ZFiberRef. 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]): ZFiberRef[EC, ED, C, D]

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

    Folds over the error and value types of the ZFiberRef, 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: IO[EB, B]

    Reads the value associated with the current fiber.

    Reads the value associated with the current fiber. Returns initial value if no value was set or inherited from parent.

  4. abstract def initialValue: Either[EB, B]

    Returns the initial value or error.

  5. abstract def locally[R, EC >: EA, C](value: A)(use: ZIO[R, EC, C]): ZIO[R, EC, C]

    Returns an IO that runs with value bound to the current fiber.

    Returns an IO that runs with value bound to the current fiber.

    Guarantees that fiber data is properly restored via acquireRelease.

  6. abstract def set(value: A): IO[EA, Unit]

    Sets the value associated with the current fiber.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. def collect[C](pf: PartialFunction[B, C]): ZFiberRef[EA, Option[EB], A, C]

    Maps and filters the get value of the ZFiberRef with the specified partial function, returning a ZFiberRef 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): ZFiberRef[EA, EB, C, B]

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

  8. def contramapEither[EC >: EA, C](f: (C) => Either[EC, A]): ZFiberRef[EC, EB, C, B]

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

  9. def dimap[C, D](f: (C) => A, g: (B) => D): ZFiberRef[EA, EB, C, D]

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

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

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

  11. def dimapError[EC, ED](f: (EA) => EC, g: (EB) => ED): ZFiberRef[EC, ED, A, B]

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

  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  14. def filterInput[A1 <: A](f: (A1) => Boolean): ZFiberRef[Option[EA], EB, A1, B]

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

  15. def filterOutput(f: (B) => Boolean): ZFiberRef[EA, Option[EB], A, B]

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

  16. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  17. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. def map[C](f: (B) => C): ZFiberRef[EA, EB, A, C]

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

  21. def mapEither[EC >: EB, C](f: (B) => Either[EC, C]): ZFiberRef[EA, EC, A, C]

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

  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  25. def readOnly: ZFiberRef[EA, EB, Nothing, B]

    Returns a read only view of the ZFiberRef.

  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. def toString(): String
    Definition Classes
    AnyRef → Any
  28. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  29. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  31. def writeOnly: ZFiberRef[EA, Unit, A, Nothing]

    Returns a write only view of the ZFiberRef.

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped