p

zio

package zio

Linear Supertypes
EitherCompat, ZEnvDefinition, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. zio
  2. EitherCompat
  3. ZEnvDefinition
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait =!=[A, B] extends Serializable

    Evidence type A is not equal to type B.

    Evidence type A is not equal to type B.

    Based on https://github.com/milessabin/shapeless.

  2. trait App extends DefaultRuntime

    The entry point for a purely-functional application on the JVM.

    The entry point for a purely-functional application on the JVM.

    import zio.App
    import zio.console._
    
    object MyApp extends App {
    
      final def run(args: List[String]) =
        myAppLogic.fold(_ => 1, _ => 0)
    
      def myAppLogic =
        for {
          _ <- putStrLn("Hello! What is your name?")
          n <- getStrLn
          _ <- putStrLn("Hello, " + n + ", good to meet you!")
        } yield ()
    }
  3. abstract class CancelableFuture[+E, +A] extends Future[A] with FutureTransformCompat[A]
  4. type Canceler[R] = ZIO[R, Nothing, Any]
  5. sealed trait Cause[+E] extends Product with Serializable
  6. sealed trait Chunk[+A] extends AnyRef

    A Chunk[A] represents a chunk of values of type A.

    A Chunk[A] represents a chunk of values of type A. Chunks are designed are usually backed by arrays, but expose a purely functional, safe interface to the underlying elements, and they become lazy on operations that would be costly with arrays, such as repeated concatenation.

  7. trait DefaultRuntime extends Runtime[ZEnv]
  8. sealed trait Exit[+E, +A] extends Product with Serializable

    An Exit[E, A] describes the result of executing an IO value.

    An Exit[E, A] describes the result of executing an IO value. The result is either succeeded with a value A, or failed with a Cause[E].

  9. trait Fiber[+E, +A] extends AnyRef

    A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention).

    A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention). Fibers are spawned by forking IO actions, which, conceptually at least, runs them concurrently with the parent IO action.

    Fibers can be joined, yielding their result other fibers, or interrupted, which terminates the fiber with a runtime error.

    Fork-Join Identity: fork >=> join = id

    for {
      fiber1 <- io1.fork
      fiber2 <- io2.fork
      _      <- fiber1.interrupt(e)
      a      <- fiber2.join
    } yield a
  10. final case class FiberFailure(cause: Cause[Any]) extends Throwable with Product with Serializable

    Represents a failure in a fiber.

    Represents a failure in a fiber. This could be caused by some non- recoverable error, such as a defect or system error, by some typed error, or by interruption (or combinations of all of the above).

    This class is used to wrap ZIO failures into something that can be thrown, to better integrate with Scala exception handling.

  11. type FiberId = Long
  12. final class FiberRef[A] extends Serializable

    Fiber's counterpart for Java's ThreadLocal.

    Fiber's counterpart for Java's ThreadLocal. Value is automatically propagated to child on fork and merged back in after joining child.

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

    result will be equal to "Hi!" as changes done by child were merged on join.

    FiberRef#make also allows specifying how the values will be combined when joining. By default this will use the value of the joined fiber. for { fiberRef <- FiberRef.make(0, math.max) child <- fiberRef.update(_ + 1).fork _ <- fiberRef.update(_ + 2) _ <- child.join value <- fiberRef.get } yield value }}}

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

  13. sealed trait FunctionIO[+E, -A, +B] extends Serializable

    A FunctionIO[E, A, B] is an effectful function from A to B, which might fail with an E.

    A FunctionIO[E, A, B] is an effectful function from A to B, which might fail with an E.

    This is the moral equivalent of A => IO[E, B], and, indeed, FunctionIO extends this function type, and can be used in the same way.

    The main advantage to using FunctionIO is that it provides you a means of importing an impure function A => B into FunctionIO[E, A, B], without actually wrapping the result of the function in an IO value.

    This allows the implementation to aggressively fuse operations on impure functions, which in turn can result in significantly higher-performance and far less heap utilization than equivalent approaches modeled with IO.

    The implementation allows you to lift functions from A => IO[E, B] into a FunctionIO[E, A, B]. Such functions cannot be optimized, but will be handled correctly and can work in conjunction with optimized (fused) FunctionIO.

    Those interested in learning more about modeling effects with FunctionIO are encouraged to read John Hughes paper on the subject: Generalizing Monads to Arrows (www.cse.chalmers.se/~rjmh/Papers/arrows.pdf). The implementation in this file contains many of the same combinators as Hughes implementation.

    A word of warning: while even very complex code can be expressed in FunctionIO, there is a point of diminishing return. If you find yourself using deeply nested tuples to propagate information forward, it may be no faster than using IO.

    Given the following two FunctionIO:

    val readLine = FunctionIO.impureVoid((_ : Unit) => scala.Console.readLine())
    val printLine = FunctionIO.impureVoid((line: String) => println(line))

    Then the following two programs are equivalent:

    // Program 1
    val program1: UIO[Unit] =
      for {
        name <- getStrLn
        _    <- putStrLn("Hello, " + name)
      } yield ())
    
    // Program 2
    val program2: UIO[Unit] = (readLine >>> FunctionIO.fromFunction("Hello, " + _) >>> printLine)(())

    Similarly, the following two programs are equivalent:

    // Program 1
    val program1: UIO[Unit] =
      for {
        line1 <- getStrLn
        line2 <- getStrLn
        _     <- putStrLn("You wrote: " + line1 + ", " + line2)
      } yield ())
    
    // Program 2
    val program2: UIO[Unit] =
      (readLine.zipWith(readLine)("You wrote: " + _ + ", " + _) >>> printLine)(())

    In both of these examples, the FunctionIO program is faster because it is able to perform fusion of effectful functions.

  14. type IO[+E, +A] = ZIO[Any, E, A]
  15. sealed abstract class InterruptStatus extends Serializable with Product

    The InterruptStatus of a fiber determines whether or not it can be interrupted.

    The InterruptStatus of a fiber determines whether or not it can be interrupted. The status can change over time in different regions.

  16. type Managed[+E, +A] = ZManaged[Any, E, A]
  17. trait ManagedApp extends DefaultRuntime
  18. final class Promise[E, A] extends AnyVal with Serializable

    A promise represents an asynchronous variable, of zio.IO type, that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling await) and automatically resume when the variable is set.

    A promise represents an asynchronous variable, of zio.IO type, that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling await) and automatically resume when the variable is set.

    Promises can be used for building primitive actions whose completions require the coordinated action of multiple fibers, and for building higher-level concurrent or asynchronous structures.

    for {
      promise <- Promise.make[Nothing, Int]
      _       <- promise.succeed(42).delay(1.second).fork
      value   <- promise.await // Resumes when forked fiber completes promise
    } yield value
  19. type Queue[A] = ZQueue[Any, Nothing, Any, Nothing, A, A]
  20. type RIO[-R, +A] = ZIO[R, Throwable, A]
  21. type RManaged[-R, +A] = ZManaged[R, Throwable, A]
  22. final class Ref[A] extends AnyVal with Serializable

    A mutable atomic reference for the IO monad.

    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.make(2)
      v   <- ref.update(_ + 3)
      _   <- console.putStrLn("Value = " + v) // Value = 5
    } yield ()
  23. final class RefM[A] extends Serializable

    A mutable atomic reference for the IO monad.

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

    Unlike Ref, RefM allows effects in atomic operations, which makes the structure slower but more powerful than Ref.

    for {
      ref <- RefM(2)
      v   <- ref.update(_ + putStrLn("Hello World!").attempt.unit *> IO.succeed(3))
      _   <- putStrLn("Value = " + v) // Value = 5
    } yield ()
  24. final case class Reservation[-R, +E, +A](acquire: ZIO[R, E, A], release: (Exit[Any, Any]) ⇒ ZIO[R, Nothing, Any]) extends Product with Serializable

    A Reservation[-R, +E, +A] encapsulates resource acquisition and disposal without specifying when or how that resource might be used.

    A Reservation[-R, +E, +A] encapsulates resource acquisition and disposal without specifying when or how that resource might be used.

    See ZManaged#reserve and ZIO#reserve for details of usage.

  25. trait Runtime[+R] extends AnyRef

    A Runtime[R] is capable of executing tasks within an environment R.

  26. type Schedule[-A, +B] = ZSchedule[Any, A, B]
  27. final class Semaphore extends Serializable

    An asynchronous semaphore, which is a generalization of a mutex.

    An asynchronous semaphore, which is a generalization of a mutex. Semaphores have a certain number of permits, which can be held and released concurrently by different parties. Attempts to acquire more permits than available result in the acquiring fiber being suspended until the specified number of permits become available.

  28. sealed abstract class SuperviseStatus extends Serializable with Product
  29. type Task[+A] = ZIO[Any, Throwable, A]
  30. type TaskManaged[+A] = ZManaged[Any, Throwable, A]
  31. sealed abstract class TracingStatus extends Serializable with Product

    Whether ZIO Tracing is enabled for the current fiber in the current region.

  32. type UIO[+A] = ZIO[Any, Nothing, A]
  33. type UManaged[+A] = ZManaged[Any, Nothing, A]
  34. type URIO[-R, +A] = ZIO[R, Nothing, A]
  35. type URManaged[-R, +A] = ZManaged[R, Nothing, A]
  36. type ZEnv = Clock with Console with System with Random with Blocking
    Definition Classes
    ZEnvDefinition
  37. trait ZEnvDefinition extends AnyRef
  38. sealed trait ZIO[-R, +E, +A] extends Serializable

    A ZIO[R, E, A] ("Zee-Oh of Are Eeh Aye") is an immutable data structure that models an effectful program.

    A ZIO[R, E, A] ("Zee-Oh of Are Eeh Aye") is an immutable data structure that models an effectful program. The effect requires an environment R, and the effect may fail with an error E or produce a single A.

    Conceptually, this structure is equivalent to ReaderT[R, EitherT[UIO, E, ?]] for some infallible effect monad UIO, but because monad transformers perform poorly in Scala, this data structure bakes in the reader effect of ReaderT with the recoverable error effect of EitherT without runtime overhead.

    ZIO values are ordinary immutable values, and may be used like any other value in purely functional code. Because ZIO values just *model* effects (like input / output), which must be interpreted by a separate runtime system, ZIO values are entirely pure and do not violate referential transparency.

    ZIO values can efficiently describe the following classes of effects:

    • Pure ValuesZIO.succeed
    • Error EffectsZIO.fail
    • Synchronous EffectsIO.effect
    • Asynchronous EffectsIO.effectAsync
    • Concurrent EffectsIO#fork
    • Resource EffectsIO#bracket
    • Contextual EffectsZIO.access

    The concurrency model is based on fibers, a user-land lightweight thread, which permit cooperative multitasking, fine-grained interruption, and very high performance with large numbers of concurrently executing fibers.

    ZIO values compose with other ZIO values in a variety of ways to build complex, rich, interactive applications. See the methods on ZIO for more details about how to compose ZIO values.

    In order to integrate with Scala, ZIO values must be interpreted into the Scala runtime. This process of interpretation executes the effects described by a given immutable ZIO value. For more information on interpreting ZIO values, see the default interpreter in DefaultRuntime or the safe main function in App.

  39. final case class ZManaged[-R, +E, +A](reserve: ZIO[R, E, Reservation[R, E, A]]) extends Product with Serializable

    A ZManaged[R, E, A] is a managed resource of type A, which may be used by invoking the use method of the resource.

    A ZManaged[R, E, A] is a managed resource of type A, which may be used by invoking the use method of the resource. The resource will be automatically acquired before the resource is used, and automatically released after the resource is used.

    Resources do not survive the scope of use, meaning that if you attempt to capture the resource, leak it from use, and then use it after the resource has been consumed, the resource will not be valid anymore and may fail with some checked error, as per the type of the functions provided by the resource.

  40. trait ZQueue[-RA, +EA, -RB, +EB, -A, +B] extends Serializable

    A ZQueue[RA, EA, RB, EB, A, B] is a lightweight, asynchronous queue into which values of type A can be enqueued and of which elements of type B can be dequeued.

    A ZQueue[RA, EA, RB, EB, A, B] is a lightweight, asynchronous queue into which values of type A can be enqueued and of which elements of type B can be dequeued. The queue's enqueueing operations may utilize an environment of type RA and may fail with errors of type EA. The dequeueing operations may utilize an environment of type RB and may fail with errors of type EB.

  41. trait ZSchedule[-R, -A, +B] extends Serializable

    Defines a stateful, possibly effectful, recurring schedule of actions.

    Defines a stateful, possibly effectful, recurring schedule of actions.

    A ZSchedule[R, A, B] consumes A values, and based on the inputs and the internal state, decides whether to continue or halt. Every decision is accompanied by a (possibly zero) delay, and an output value of type B.

    Schedules compose in each of the following ways:

    1. Intersection, using the && operator, which requires that both schedules continue, using the longer of the two durations. 2. Union, using the || operator, which requires that only one schedule continues, using the shorter of the two durations. 3. Sequence, using the <||> operator, which runs the first schedule until it ends, and then switches over to the second schedule.

    Schedule[R, A, B] forms a profunctor on [A, B], an applicative functor on B, and a monoid, allowing rich composition of different schedules.

  42. final case class ZTrace(fiberId: FiberId, executionTrace: List[ZTraceElement], stackTrace: List[ZTraceElement], parentTrace: Option[ZTrace]) extends Product with Serializable
  43. final class FiberLocal[A] extends Serializable

    A container for fiber-local storage.

    A container for fiber-local storage. It is the pure equivalent to Java's ThreadLocal on a fiber architecture.

    Annotations
    @deprecated
    Deprecated

    (Since version 1.0.0) use FiberRef

  44. type TaskR[-R, +A] = ZIO[R, Throwable, A]
    Annotations
    @deprecated
    Deprecated

    (Since version 1.0.0) use RIO

Value Members

  1. object <*>
  2. object =!= extends Serializable
  3. object BuildInfo extends Product with Serializable

    This object was generated by sbt-buildinfo.

  4. object Cause extends Serializable
  5. object Chunk
  6. object Exit extends Serializable
  7. object Fiber
  8. object FiberRef extends Serializable
  9. object FunctionIO extends Serializable
  10. object IO
  11. object InterruptStatus extends Serializable
  12. object Managed
  13. object Promise extends Serializable
  14. object Queue
  15. object RIO
  16. object Ref extends Serializable
  17. object RefM extends Serializable
  18. object Runtime
  19. object Schedule
  20. object Semaphore extends Serializable
  21. object SuperviseStatus extends Serializable
  22. object Task
  23. object TracingStatus extends Serializable
  24. object UIO
  25. object URIO
  26. object ZEnv
  27. object ZIO extends ZIOFunctions
  28. object ZManaged extends Serializable
  29. object ZSchedule extends Serializable
  30. object ZTrace extends Serializable

Deprecated Value Members

  1. val TaskR: RIO.type
    Annotations
    @deprecated
    Deprecated

    (Since version 1.0.0) use RIO

  2. object FiberLocal extends Serializable
    Annotations
    @deprecated
    Deprecated

    (Since version 1.0.0) use FiberRef

Inherited from EitherCompat

Inherited from ZEnvDefinition

Inherited from AnyRef

Inherited from Any

Ungrouped