Class/Object

zio

ZFiberRef

Related Docs: object ZFiberRef | package zio

Permalink

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

    Permalink

    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]

    Permalink

    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]

    Permalink

    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 locally[R, EC >: EA, C](value: A)(use: ZIO[R, EC, C]): ZIO[R, EC, C]

    Permalink

    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.

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

    Permalink

    Sets the value associated with the current fiber.

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]): ZFiberRef[EA, Option[EB], A, C]

    Permalink

    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]

    Permalink

    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]

    Permalink

    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]

    Permalink

    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]

    Permalink

    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]

    Permalink

    Transforms both the set and get errors of the ZFiberRef 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): ZFiberRef[Option[EA], EB, A1, B]

    Permalink

    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]

    Permalink

    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

    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): ZFiberRef[EA, EB, A, C]

    Permalink

    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]

    Permalink

    Transforms the get value of the ZFiberRef 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: ZFiberRef[EA, EB, Nothing, B]

    Permalink

    Returns a read only view of the ZFiberRef.

  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: ZFiberRef[EA, Unit, A, Nothing]

    Permalink

    Returns a write only view of the ZFiberRef.

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped