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.
A simple, macro-less means of creating accessors from Services.
A simple, macro-less means of creating accessors from Services. Extend the
companion object with Accessible[ServiceName]
, then simply call
Companion(_.someMethod)
, to return a ZIO effect that requires the Service
in its environment.
Example:
trait FooService { def magicNumber: UIO[Int] def castSpell(chant: String): UIO[Boolean] } object FooService extends Accessible[FooService] val example: ZIO[FooService, Nothing, Unit] = for { int <- FooService(_.magicNumber) bool <- FooService(_.castSpell("Oogabooga!")) } yield ()
A Cached is a possibly resourceful value that is loaded into memory, and which can be refreshed either manually or automatically.
A value of type CanFail[E]
provides implicit evidence that an effect with
error type E
can fail, that is, that E
is not equal to Nothing
.
A value of type CanFail[E]
provides implicit evidence that an effect with
error type E
can fail, that is, that E
is not equal to Nothing
.
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.
The implementation of balanced concatenation is based on the one for Conc-Trees in "Conc-Trees for Functional and Parallel Programming" by Aleksandar Prokopec and Martin Odersky. http://aleksandar-prokopec.com/resources/docs/lcpc-conc-trees.pdf
NOTE: For performance reasons Chunk
does not box primitive types. As a
result, it is not safe to construct chunks from heterogeneous primitive
types.
A ChunkBuilder[A]
can build a Chunk[A]
given elements of type A
.
A ChunkBuilder[A]
can build a Chunk[A]
given elements of type A
.
ChunkBuilder
is a mutable data structure that is implemented to efficiently
build chunks of unboxed primitives and for compatibility with the Scala
collection library.
ChunkCanBuildFrom
provides implicit evidence that a collection of type
Chunk[A]
can be built from elements of type A
.
ChunkCanBuildFrom
provides implicit evidence that a collection of type
Chunk[A]
can be built from elements of type A
. Since a Chunk[A]
can be
built from elements of type A
for any type A
, this implicit evidence
always exists. It is used primarily to provide proof that the target type of
a collection operation is a Chunk
to support high performance
implementations of transformation operations for chunks.
Describes a strategy for evaluating multiple effects, potentially in parallel.
Describes a strategy for evaluating multiple effects, potentially in
parallel. There are three possible execution strategies: Sequential
,
Parallel
, and ParallelN
.
An executor is responsible for executing actions.
An executor is responsible for executing actions. Each action is guaranteed to begin execution on a fresh stack frame.
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]
.
A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention and asynchronicity).
A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention and asynchronicity). Fibers are spawned by forking ZIO effects, which run concurrently with the parent effect.
Fibers can be joined, yielding their result to other fibers, or interrupted, which terminates the fiber, safely releasing all resources.
def parallel[A, B](io1: Task[A], io2: Task[B]): Task[(A, B)] = for { fiber1 <- io1.fork fiber2 <- io2.fork a <- fiber1.join b <- fiber2.join } yield (a, b)
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.
The identity of a Fiber, described by the time it began life, and a monotonically increasing sequence number generated from an atomic counter.
FiberRefs
is a data type that represents a collection of FiberRef
values.
FiberRefs
is a data type that represents a collection of FiberRef
values.
This allows safely propagating FiberRef
values across fiber boundaries, for
example between an asynchronous producer and consumer.
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.
LogLevel represents the log level associated with an individual logging operation.
LogLevel represents the log level associated with an individual logging operation. Log levels are used both to describe the granularity (or importance) of individual log statements, as well as to enable tuning verbosity of log output.
The priority of the log message. Larger values indicate higher priority.
A label associated with the log level.
The syslog severity level of the log level. LogLevel values are ZIO aspects, and therefore can be used with aspect syntax.
myEffect @@ LogLevel.Info
A NonEmptyChunk
is a Chunk
that is guaranteed to contain at least one
element.
A NonEmptyChunk
is a Chunk
that is guaranteed to contain at least one
element. As a result, operations which would not be safe when performed on
Chunk
, such as head
or reduce
, are safe when performed on
NonEmptyChunk
. Operations on NonEmptyChunk
which could potentially return
an empty chunk will return a Chunk
instead.
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
A Reloadable is an implementation of some service that can be dynamically reloaded, or swapped out for another implementation on-the-fly.
A Runtime[R]
is capable of executing tasks within an environment R
.
A RuntimeConfig
provides the minimum capabilities necessary to bootstrap
execution of ZIO
tasks.
A Schedule[Env, In, Out]
defines a recurring schedule, which consumes
values of type In
, and which returns values of type Out
.
A Schedule[Env, In, Out]
defines a recurring schedule, which consumes
values of type In
, and which returns values of type Out
.
Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible.
When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again.
Schedules compose in the following primary ways:
* Union. This performs the union of the intervals of two schedules. * Intersection. This performs the intersection of the intervals of two schedules. * Sequence. This concatenates the intervals of one schedule onto another.
In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth.
A variety of other operators exist for transforming and combining schedules,
and the companion object for Schedule
contains all common types of
schedules, both for performing retrying, as well as performing repetition.
A Scope
is the foundation of safe, composable resource management in ZIO.
A Scope
is the foundation of safe, composable resource management in ZIO. A
scope has two fundamental operators, addFinalizer
, which adds a finalizer
to the scope, and close
, which closes a scope and runs all finalizers that
have been added to the scope.
A ScopedRef is a reference whose value is associated with resources, which must be released properly.
A ScopedRef is a reference whose value is associated with resources, which must be released properly. You can both get the current value of any ScopedRef, as well as set it to a new value (which may require new resources). The reference itself takes care of properly releasing resources for the old value whenever a new value is obtained.
A Supervisor[A]
is allowed to supervise the launching and termination of
fibers, producing some visible value of type A
from the supervision.
A queue that can only be dequeued.
A queue that can only be enqueued.
A FiberRef
is ZIO's equivalent of Java's ThreadLocal
.
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.
A ZHub[RA, RB, EA, EB, A, B]
is an asynchronous message hub.
A ZHub[RA, RB, EA, EB, A, B]
is an asynchronous message hub. Publishers can
publish messages of type A
to the hub and subscribers can subscribe to take
messages of type B
from the hub. Publishing messages can require an
environment of type RA
and fail with an error of type EA
. Taking messages
can require an environment of type RB
and fail with an error of type EB
.
A ZIO[R, E, A]
value is an immutable value (called an "effect") that
describes an async, concurrent workflow.
A ZIO[R, E, A]
value is an immutable value (called an "effect") that
describes an async, concurrent workflow. In order to be executed, the
workflow requires a value of type ZEnvironment[R]
, and when executed, the
workflow will either produce a failure of type E
, or a success of type A
.
ZIO effects may informally be thought of as functions of the following form:
ZEnvironment[R] => Either[E, A]
ZIO effects model resourceful interaction with the outside world, including synchronous, asynchronous, concurrent, and parallel interaction.
The async and concurrent operations of ZIO effects are powered by fibers, which are lightweight, green threads that enable high scalability.
To run an effect, you need a Runtime
, which is capable of executing
effects. Runtimes bundle a thread pool together with the environment that
effects need.
An entry point for a ZIO application that allows sharing layers between applications.
An entry point for a ZIO application that allows sharing layers between
applications. For a simpler version that uses the default ZIO environment see
ZIOAppDefault
.
A service that contains command-line arguments of an application.
The entry point for a ZIO application.
The entry point for a ZIO application.
import zio.ZIOAppDefault import zio.Console._ object MyApp extends ZIOAppDefault { def run = for { _ <- printLine("Hello! What is your name?") n <- readLine _ <- printLine("Hello, " + n + ", good to meet you!") } yield () }
A ZLayer[E, A, B]
describes how to build one or more services in your
application.
A ZLayer[E, A, B]
describes how to build one or more services in your
application. Services can be injected into effects via ZIO#provide. Effects
can require services via ZIO.service."
Layer can be thought of as recipes for producing bundles of services, given their dependencies (other services).
Construction of services can be effectful and utilize resources that must be acquired and safely released when the services are done being utilized.
By default layers are shared, meaning that if the same layer is used twice the layer will only be allocated a single time.
Because of their excellent composition properties, layers are the idiomatic way in ZIO to create services that depend on other services.
A ZPool[E, A]
is a pool of items of type A
, each of which may be
associated with the acquisition and release of resources.
A ZPool[E, A]
is a pool of items of type A
, each of which may be
associated with the acquisition and release of resources. An attempt to get
an item A
from a pool may fail with an error of type E
.
A ZQueue[RA, RB, EA, 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, RB, EA, 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
.
A ZRef[RA, RB, EA, EB, A, B]
is a polymorphic, purely functional
description of a mutable reference.
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.
ZState[S]
models a value of type S
that can be read from and written to
during the execution of an effect.
ZState[S]
models a value of type S
that can be read from and written to
during the execution of an effect. The idiomatic way to work with ZState
is
as part of the environment using operators defined on ZIO
. For example:
final case class MyState(counter: Int) for { _ <- ZIO.updateState[MyState](state => state.copy(counter = state.counter + 1)) count <- ZIO.getStateWith[MyState](_.counter) } yield count
Because ZState
is typically used as part of the environment, it is
recommended to define your own state type S
such as MyState
above rather
than using a type such as Int
to avoid the risk of ambiguity.
To run an effect that depends on some state, create the initial state with
the make
constructor and then use toLayer
to convert it into a service
builder that you can provide along with your application's other services.
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.exitCode val myAppLogic = for { _ <- printLine("Hello! What is your name?") n <- readLine _ <- printLine("Hello, " + n + ", good to meet you!") } yield () }
(Since version 2.0.0) Use zio.ZIOAppDefault
(Since version 2.0.0) Use zio.Runtime
(Since version 2.0.0) use ERef.Synchronized
(Since version 2.0.0) use Ref.Synchronized
The entry point for a purely-functional application on the JVM.
The entry point for a purely-functional application on the JVM.
import zio.ZApp import zio.Console._ object MyApp extends ZApp[Console] { def environment: Console = ConsoleLive final def run(args: List[String]) = myAppLogic.exitCode def myAppLogic = for { _ <- printLine("Hello! What is your name?") n <- readLine _ <- printLine("Hello, " + n + ", good to meet you!") } yield () }
(Since version 2.0.0) Use zio.ZIOApp
(Since version 2.0.0) Use Runtime
(Since version 2.0.0) use ZRef.Synchronized
This object was generated by sbt-buildinfo.