Class/Object

scalaz.zio

Ref

Related Docs: object Ref | package zio

Permalink

final class Ref[A] extends AnyVal

A mutable atomic reference for the IO monad. This is the IO equivalent of a volatile var, augmented with atomic operations, which make it useful as a reasonably efficient (if low-level) concurrency primitive.

for {
  ref <- Ref(2)
  v   <- ref.modify(_ + 3)
  _   <- putStrLn("Value = " + v.debug) // Value = 5
} yield ()
Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Ref
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

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

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

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

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

    Permalink
    Definition Classes
    Any
  5. final def compareAndSet(prev: A, next: A): IO[Nothing, Boolean]

    Permalink

    Compares and sets the value of the Ref if and only if it is eq to the specified value.

    Compares and sets the value of the Ref if and only if it is eq to the specified value. Returns whether or not the ref was modified.

  6. final def get: IO[Nothing, A]

    Permalink

    Reads the value from the Ref.

  7. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  8. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  9. final def modify[B](f: (A) ⇒ (B, A)): IO[Nothing, B]

    Permalink

    Atomically modifies the Ref with the specified function, which computes a return value for the modification.

    Atomically modifies the Ref with the specified function, which computes a return value for the modification. This is a more powerful version of update.

  10. final def set(a: A): IO[Nothing, Unit]

    Permalink

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

  11. final def setLater(a: A): IO[Nothing, Unit]

    Permalink

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

  12. def toString(): String

    Permalink
    Definition Classes
    Any
  13. final def trySet(a: A): IO[Nothing, Boolean]

    Permalink

    Attempts to write a new value to the Ref, but aborts immediately under concurrent modification of the value by other fibers.

  14. final def update(f: (A) ⇒ A): IO[Nothing, A]

    Permalink

    Atomically modifies the Ref with the specified function.

    Atomically modifies the Ref with the specified function. This is not implemented in terms of modify purely for performance reasons.

Inherited from AnyVal

Inherited from Any

Ungrouped