A ZIOConstructor[Input]
knows how to construct a ZIO
value from an
input of type Input
.
A ZIOConstructor[Input]
knows how to construct a ZIO
value from an
input of type Input
. This allows the type of the ZIO
value constructed
to depend on Input
. The constructed ZIO
value is guaranteed not to
require any services not included in Environment
or to be able to fail in
any ways not described by Error
.
The level of parallelism for parallel operators.
Submerges the error case of an Either
into the ZIO
.
Submerges the error case of an Either
into the ZIO
. The inverse
operation of IO.either
.
Uncurried version.
Uncurried version. Doesn't offer curried syntax and has worse type-inference characteristics, but guarantees no extra allocations of intermediate zio.ZIO.AcquireExit and zio.ZIO.ReleaseExit objects.
Acquires a resource, uses the resource, and then releases the resource.
Acquires a resource, uses the resource, and then releases the resource.
Neither the acquisition nor the release will be interrupted, and the
resource is guaranteed to be released, so long as the acquire
effect
succeeds. If use
fails, then after release, the returned effect will fail
with the same error.
Uncurried version.
Uncurried version. Doesn't offer curried syntax and have worse type-inference characteristics, but guarantees no extra allocations of intermediate zio.ZIO.Acquire and zio.ZIO.Release objects.
When this effect represents acquisition of a resource (for example, opening
a file, launching a thread, etc.), acquireReleaseWith
can be used to
ensure the acquisition is not interrupted and the resource is always
released.
When this effect represents acquisition of a resource (for example, opening
a file, launching a thread, etc.), acquireReleaseWith
can be used to
ensure the acquisition is not interrupted and the resource is always
released.
The function does two things:
release
effect will not be
interrupted, and will be executed so long as this effect successfully
acquires the resource.In between acquisition and release of the resource, the use
effect is
executed.
If the release
effect fails, then the entire effect will fail even if the
use
effect succeeds. If this fail-fast behavior is not desired, errors
produced by the release
effect can be caught and ignored.
openFile("data.json").acquireReleaseWith(closeFile) { file => for { header <- readHeader(file) ... } yield result }
Makes an explicit check to see if the fiber has been interrupted, and if so, performs self-interruption
Imports an asynchronous side-effect into a pure ZIO
value.
Imports an asynchronous side-effect into a pure ZIO
value. See
asyncMaybe
for the more expressive variant of this function that can
return a value synchronously.
The callback function ZIO[R, E, A] => Any
must be called at most once.
The list of fibers, that may complete the async callback, is used to provide better diagnostics.
Imports an asynchronous side-effect into a ZIO effect.
Imports an asynchronous side-effect into a ZIO effect. The side-effect has the option of returning the value synchronously, which is useful in cases where it cannot be determined if the effect is synchronous or asynchronous until the side-effect is actually executed. The effect also has the option of returning a canceler, which will be used by the runtime to cancel the asynchronous effect if the fiber executing the effect is interrupted.
If the register function returns a value synchronously, then the callback
function ZIO[R, E, A] => Any
must not be called. Otherwise the callback
function must be called at most once.
The list of fibers, that may complete the async callback, is used to provide better diagnostics.
Imports an asynchronous effect into a pure ZIO
value, possibly returning
the value synchronously.
Imports an asynchronous effect into a pure ZIO
value, possibly returning
the value synchronously.
If the register function returns a value synchronously, then the callback
function ZIO[R, E, A] => Any
must not be called. Otherwise the callback
function must be called at most once.
The list of fibers, that may complete the async callback, is used to provide better diagnostics.
Imports an asynchronous effect into a pure ZIO
value.
Imports an asynchronous effect into a pure ZIO
value. This formulation is
necessary when the effect is itself expressed in terms of ZIO
.
Imports a synchronous side-effect into a pure ZIO
value, translating any
thrown exceptions into typed failed effects creating with ZIO.fail
.
Imports a synchronous side-effect into a pure ZIO
value, translating any
thrown exceptions into typed failed effects creating with ZIO.fail
.
def printLine(line: String): Task[Unit] = Task.attempt(println(line))
Imports a synchronous effect that does blocking IO into a pure value.
Imports a synchronous effect that does blocking IO into a pure value, with a custom cancel effect.
Imports a synchronous effect that does blocking IO into a pure value, with a custom cancel effect.
If the returned ZIO
is interrupted, the blocked thread running the
synchronous effect will be interrupted via the cancel effect.
Imports a synchronous effect that does blocking IO into a pure value,
refining the error type to java.io.IOException
.
Imports a synchronous effect that does blocking IO into a pure value.
Imports a synchronous effect that does blocking IO into a pure value.
If the returned ZIO
is interrupted, the blocked thread running the
synchronous effect will be interrupted via Thread.interrupt
.
Note that this adds significant overhead. For performance sensitive
applications consider using attemptBlocking
or
attemptBlockingCancelable
.
Locks the specified effect to the blocking thread pool.
Retrieves the executor for all blocking tasks.
Checks the interrupt status, and produces the effect returned by the specified callback.
Evaluate each effect in the structure from left to right, collecting the the successful values and discarding the empty cases.
Evaluate each effect in the structure from left to right, collecting the
the successful values and discarding the empty cases. For a parallel
version, see collectPar
.
Evaluate each effect in the structure from left to right, collecting the the successful values and discarding the empty cases.
Evaluate each effect in the structure from left to right, collecting the
the successful values and discarding the empty cases. For a parallel
version, see collectPar
.
Evaluate each effect in the structure from left to right, and collect the results.
Evaluate each effect in the structure from left to right, and collect the
results. For a parallel version, see collectAllPar
.
Evaluate effect if present, and return its result as Option[A]
.
Evaluate each effect in the structure from left to right, and collect the results.
Evaluate each effect in the structure from left to right, and collect the
results. For a parallel version, see collectAllPar
.
Evaluate each effect in the structure from left to right, and collect the results.
Evaluate each effect in the structure from left to right, and collect the
results. For a parallel version, see collectAllPar
.
Evaluate each effect in the structure from left to right, and collect the results.
Evaluate each effect in the structure from left to right, and collect the
results. For a parallel version, see collectAllPar
.
Evaluate each effect in the structure from left to right, and discard the results.
Evaluate each effect in the structure from left to right, and discard the
results. For a parallel version, see collectAllParDiscard
.
Evaluate each effect in the structure in parallel, and collect the results.
Evaluate each effect in the structure in parallel, and collect the results.
For a sequential version, see collectAll
.
Evaluate each effect in the structure in parallel, and collect the results.
Evaluate each effect in the structure in parallel, and collect the results.
For a sequential version, see collectAll
.
Evaluate each effect in the structure in parallel, and collect the results.
Evaluate each effect in the structure in parallel, and collect the results.
For a sequential version, see collectAll
.
Evaluate each effect in the structure in parallel, and collect the results.
Evaluate each effect in the structure in parallel, and collect the results.
For a sequential version, see collectAll
.
Evaluate each effect in the structure in parallel, and discard the results.
Evaluate each effect in the structure in parallel, and discard the results.
For a sequential version, see collectAllDiscard
.
Evaluate and run each effect in the structure and collect discarding failed ones.
Evaluate and run each effect in the structure in parallel, and collect discarding failed ones.
Evaluate each effect in the structure with collectAll
, and collect the
results with given partial function.
Evaluate each effect in the structure with collectAllPar
, and collect the
results with given partial function.
Collects the first element of the Iterable[A]
for which the effectual
function f
returns Some
.
Evaluate each effect in the structure from left to right, collecting the the successful values and discarding the empty cases.
Evaluate each effect in the structure from left to right, collecting the
the successful values and discarding the empty cases. For a parallel
version, see collectPar
.
Evaluate each effect in the structure in parallel, collecting the the successful values and discarding the empty cases.
Similar to Either.cond, evaluate the predicate, return the given A as success if predicate returns true, and the given E as error otherwise
Similar to Either.cond, evaluate the predicate, return the given A as success if predicate returns true, and the given E as error otherwise
For effectful conditionals, see ZIO.ifZIO
Prints the specified message to the console for debugging purposes.
Returns information about the current fiber, such as its identity.
Constructs an effect based on information about the current fiber, such as its identity.
Returns an effect that dies with the specified Throwable
.
Returns an effect that dies with the specified Throwable
. This method can
be used for terminating a fiber because a defect has been detected in the
code.
Returns an effect that dies with a java.lang.RuntimeException having the specified text message.
Returns an effect that dies with a java.lang.RuntimeException having the specified text message. This method can be used for terminating a fiber because a defect has been detected in the code.
Returns an effect from a zio.Exit value.
Accesses the whole environment of the effect.
Accesses the environment of the effect.
Effectually accesses the environment of the effect.
Retrieves the executor for this effect.
Determines whether any element of the Iterable[A]
satisfies the effectual
predicate f
.
Returns an effect that models failure with the specified error.
Returns an effect that models failure with the specified error. The moral
equivalent of throw
for pure code.
Returns an effect that models failure with the specified Cause
.
Returns the FiberId
of the fiber executing the effect that calls this
method.
Filters the Set[A] using the specified effectual predicate.
Filters the collection using the specified effectual predicate.
Filters the Set[A] using the specified effectual predicate, removing all elements that satisfy the predicate.
Filters the collection using the specified effectual predicate, removing all elements that satisfy the predicate.
Filters the Set[A] in parallel using the specified effectual predicate, removing all elements that satisfy the predicate.
Filters the Set[A] in parallel using the specified effectual predicate, removing all elements that satisfy the predicate.
See zio.ZIO.filterNot[R,E,A](as:Set* for a sequential version.
Filters the collection in parallel using the specified effectual predicate, emoving all elements that satisfy the predicate.
Filters the collection in parallel using the specified effectual predicate, emoving all elements that satisfy the predicate.
See zio.ZIO.filterNot[R,E,A,Collection* for a sequential version.
Filters the Set[A] in parallel using the specified effectual predicate.
Filters the Set[A] in parallel using the specified effectual predicate.
See zio.ZIO.filter[R,E,A,Collection* for a sequential version.
Filters the collection in parallel using the specified effectual predicate.
Filters the collection in parallel using the specified effectual predicate.
See zio.ZIO.filter[R,E,A,Collection* for a sequential version.
Returns an effect that runs the first effect and in case of failure, runs each of the specified effects in order until one of them succeeds.
Returns an effect that first executes the outer effect, and then executes the inner effect, returning the value from the inner effect, and effectively flattening a nested effect.
Folds an Iterable[A] using an effectual function f, working sequentially from left to right.
Folds an Iterable[A] using an effectual function f, working sequentially from right to left.
Determines whether all elements of the Iterable[A]
satisfy the effectual
predicate f
.
Applies the function f
to each element of the NonEmptyChunk[A]
and
returns the results in a new NonEmptyChunk[B]
.
Applies the function f
to each element of the NonEmptyChunk[A]
and
returns the results in a new NonEmptyChunk[B]
.
For a parallel version of this method, see foreachPar
. If you do not need
the results, see foreachDiscard
for a more efficient implementation.
Applies the function f
if the argument is non-empty and returns the
results in a new Option[B]
.
Applies the function f
to each element of the Map[Key, Value]
and
returns the results in a new Map[Key2, Value2]
.
Applies the function f
to each element of the Map[Key, Value]
and
returns the results in a new Map[Key2, Value2]
.
For a parallel version of this method, see foreachPar
. If you do not need
the results, see foreachDiscard
for a more efficient implementation.
Applies the function f
to each element of the Array[A]
and returns the
results in a new Array[B]
.
Applies the function f
to each element of the Array[A]
and returns the
results in a new Array[B]
.
For a parallel version of this method, see foreachPar
. If you do not need
the results, see foreachDiscard
for a more efficient implementation.
Applies the function f
to each element of the Set[A]
and returns the
results in a new Set[B]
.
Applies the function f
to each element of the Set[A]
and returns the
results in a new Set[B]
.
For a parallel version of this method, see foreachPar
. If you do not need
the results, see foreachDiscard
for a more efficient implementation.
Applies the function f
to each element of the Collection[A]
and returns
the results in a new Collection[B]
.
Applies the function f
to each element of the Collection[A]
and returns
the results in a new Collection[B]
.
For a parallel version of this method, see foreachPar
. If you do not need
the results, see foreach_
for a more efficient implementation.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects sequentially.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects sequentially.
Equivalent to foreach(as)(f).unit
, but without the cost of building the
list of results.
Applies the function f
to each element of the Collection[A]
and returns
the result in a new Collection[B]
using the specified execution strategy.
Applies the function f
to each element of the NonEmptyChunk[A]
in
parallel, and returns the results in a new NonEmptyChunk[B]
.
Applies the function f
to each element of the NonEmptyChunk[A]
in
parallel, and returns the results in a new NonEmptyChunk[B]
.
For a sequential version of this method, see foreach
.
Applies the function f
to each element of the Map[Key, Value]
in
parallel and returns the results in a new Map[Key2, Value2]
.
Applies the function f
to each element of the Map[Key, Value]
in
parallel and returns the results in a new Map[Key2, Value2]
.
For a sequential version of this method, see foreach
.
Applies the function f
to each element of the Array[A]
in parallel, and
returns the results in a new Array[B]
.
Applies the function f
to each element of the Array[A]
in parallel, and
returns the results in a new Array[B]
.
For a sequential version of this method, see foreach
.
Applies the function f
to each element of the Set[A]
in parallel, and
returns the results in a new Set[B]
.
Applies the function f
to each element of the Set[A]
in parallel, and
returns the results in a new Set[B]
.
For a sequential version of this method, see foreach
.
Applies the function f
to each element of the Collection[A]
in
parallel, and returns the results in a new Collection[B]
.
Applies the function f
to each element of the Collection[A]
in
parallel, and returns the results in a new Collection[B]
.
For a sequential version of this method, see foreach
.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
For a sequential version of this method, see foreachDiscard
.
Optimized to avoid keeping full tree of effects, so that method could be able to handle large input sequences. Behaves almost like this code:
as.foldLeft(ZIO.unit) { (acc, a) => acc.zipParLeft(f(a)) }
Additionally, interrupts all effects on any failure.
Returns an effect that forks all of the specified values, and returns a composite fiber that produces a list of their results, in order.
Returns an effect that forks all of the specified values, and returns a composite fiber that produces unit.
Returns an effect that forks all of the specified values, and returns a composite fiber that produces unit. This version is faster than forkAll in cases where the results of the forked fibers are not needed.
Retrieves the scope that will be used to supervise forked effects.
Captures the fork scope, before overriding it with the specified new scope, passing a function that allows restoring the fork scope to what it was originally.
Retrieves the scope that will be used to supervise forked effects.
Constructs a ZIO
value of the appropriate type for the specified input.
Lifts an Either
into a ZIO
value.
Lifts an Either
into a ZIO
value.
Creates a ZIO
value that represents the exit value of the specified
fiber.
Creates a ZIO
value that represents the exit value of the specified
fiber.
Imports a function that creates a scala.concurrent.Future from an
scala.concurrent.ExecutionContext into a ZIO
.
Imports a function that creates a scala.concurrent.Future from an
scala.concurrent.ExecutionContext into a ZIO
.
Imports a function that creates a scala.concurrent.Future from an
scala.concurrent.ExecutionContext into a ZIO
. The provided
ExecutionContext
will interrupt the Future
between asynchronous
operations such as map
and flatMap
if this effect is interrupted. Note
that no attempt will be made to interrupt a Future
blocking on a
synchronous operation and that the Future
must be created using the
provided ExecutionContext
.
Lifts an Option
into a ZIO
but preserves the error as an option in the
error channel, making it easier to compose in some scenarios.
Imports a Scala.js promise into a ZIO
.
Imports a Scala.js promise into a ZIO
.
Imports a scala.concurrent.Promise we generate a future from promise, and we pass to [fromFuture] to transform into Task[A]
Lifts a Try
into a ZIO
.
Returns a collection of all FiberRef
values for the fiber running this
effect.
Lifts an Option into a ZIO, if the option is not defined it fails with NoSuchElementException.
Lifts an Option into a IO, if the option is not defined it fails with Unit.
Lifts an Option into a ZIO.
Lifts an Option into a ZIO. If the option is not defined, fail with the e
value.
Gets a state from the environment.
Gets a state from the environment and uses it to run the specified function.
Runs onTrue
if the result of b
is true
and onFalse
otherwise.
Like never, but fibers that running this effect won't be garbage collected unless interrupted.
Returns an effect that is interrupted as if by the fiber calling this method.
Returns an effect that is interrupted as if by the specified fiber.
Prefix form of ZIO#interruptible
.
Makes the effect interruptible, but passes it a restore function that can be used to restore the inherited interruptibility from whatever region the effect is composed into.
Iterates with the specified effectual function.
Iterates with the specified effectual function. The moral equivalent of:
var s = initial while (cont(s)) { s = body(s) } s
Returns an effect with the value on the left part.
Logs the specified message at the current log level.
Logs the specified message at the debug log level.
Logs the specified message at the error log level.
Logs the specified cause as an error.
Logs the specified message at the fatal log level.
Logs the specified message at the informational log level.
Adjusts the label for the current logging span.
Adjusts the label for the current logging span.
ZIO.logSpan("parsing") { parseRequest(req) }
Logs the specified message at the warning log level.
Loops with the specified effectual function, collecting the results into a list.
Loops with the specified effectual function, collecting the results into a list. The moral equivalent of:
var s = initial var as = List.empty[A] while (cont(s)) { as = body(s) :: as s = inc(s) } as.reverse
Loops with the specified effectual function purely for its effects.
Loops with the specified effectual function purely for its effects. The moral equivalent of:
var s = initial while (cont(s)) { body(s) s = inc(s) }
Returns a memoized version of the specified effectual function.
Merges an Iterable[IO]
to a single IO, working sequentially.
Merges an Iterable[IO]
to a single IO, working in parallel.
Merges an Iterable[IO]
to a single IO, working in parallel.
Due to the parallel nature of this combinator, f
must be both:
f(a, b) == f(b, a)
f(a, f(b, c)) == f(f(a, b), c)
It's unsafe to execute side effects inside f
, as f
may be executed more
than once for some of in
elements during effect execution.
Returns a effect that will never produce anything.
Returns a effect that will never produce anything. The moral equivalent of
while(true) {}
, only without the wasted CPU cycles. Fibers that suspended
running this effect are automatically garbage collected on the JVM, because
they cannot be reactivated.
Returns an effect with the empty value.
Lifts an Option into a IO.
Lifts an Option into a IO. If the option is empty it succeeds with Unit. If the option is defined it fails with the content.
Lifts an Option into a IO.
Lifts an Option into a IO. If the option is empty it succeeds with Unit. If the option is defined it fails with an error adapted with f.
Returns a new effect where boolean value of this effect is negated.
Returns an effect that will execute the specified effect fully on the provided executor, before returning to the default executor.
Returns an effect that will execute the specified effect fully on the provided executor, before returning to the default executor. See ZIO!.onExecutor.
Retrieves the maximum number of fibers for parallel operators or None
if
it is unbounded.
Retrieves the current maximum number of fibers for parallel operators and uses it to run the specified effect.
Feeds elements of type A
to a function f
that returns an effect.
Feeds elements of type A
to a function f
that returns an effect.
Collects all successes and failures in a tupled fashion.
Feeds elements of type A
to a function f
that returns an effect.
Feeds elements of type A
to a function f
that returns an effect.
Collects all successes and failures in parallel and returns the result as a
tuple.
Given an environment R
, returns a function that can supply the
environment to programs that require it, removing their need for any
specific environment.
Given an environment R
, returns a function that can supply the
environment to programs that require it, removing their need for any
specific environment.
This is similar to dependency injection, and the provide
function can be
thought of as inject
.
Races an IO[E, A]
against zero or more other effects.
Races an IO[E, A]
against zero or more other effects. Yields either the
first success or the last failure.
Reduces an Iterable[IO]
to a single IO
, working sequentially.
Reduces an Iterable[IO]
to a single IO
, working in parallel.
Replicates the given effect n
times.
Replicates the given effect n
times. If 0 or negative numbers are given,
an empty Iterable
will be returned. This method is more efficient than
using List.fill
or similar methods, because the returned Iterable
consumes only a small amount of heap regardless of n
.
Performs this effect the specified number of times and collects the results.
Performs this effect the specified number of times, discarding the results.
Acquires a resource, uses the resource, and then releases the resource.
Acquires a resource, uses the resource, and then releases the resource.
However, unlike acquireReleaseWith
, the separation of these phases allows
the acquisition to be interruptible.
Useful for concurrent data structures and other cases where the 'deallocator' can tell if the allocation succeeded or not just by inspecting internal / external state.
Returns an effect with the value on the right part.
Returns an effect that accesses the runtime, which can be used to (unsafely) execute tasks.
Returns an effect that accesses the runtime, which can be used to (unsafely) execute tasks. This is useful for integration with legacy code that must call back into ZIO code.
Retrieves the runtimeConfig that this effect is running on.
Passes the fiber's scope to the specified function, which creates an effect that will be returned from this method.
Accesses the specified service in the environment of the effect.
Accesses the service corresponding to the specified key in the environment.
Accesses the specified service in the environment of the effect.
Accesses the specified service in the environment of the effect.
Especially useful for creating "accessor" methods on Services' companion objects.
def foo(int: Int) = ZIO.serviceWith[Foo](_.foo(int))
Effectfully accesses the specified service in the environment of the effect.
Effectfully accesses the specified service in the environment of the effect.
Especially useful for creating "accessor" methods on Services' companion objects.
def foo(int: Int) = ZIO.serviceWithZIO[Foo](_.foo(int))
Sets the FiberRef
values for the fiber running this effect to the values
in the specified collection of FiberRef
values.
Sets the runtime configuration to the specified value.
Sets a state in the environment to the specified value.
Returns an effect that shifts execution to the specified executor.
Returns an effect that shifts execution to the specified executor. This is useful to specify a default executor that effects sequenced after this one will be run on if they are not shifted somewhere else. It can also be used to implement higher level operators to manage where an effect is run such as ZIO!.onExecutor and ZIO!.onExecutionContext.
Returns an effect that suspends for the specified duration.
Returns an effect that suspends for the specified duration. This method is asynchronous, and does not actually block the fiber executing the effect.
Returns an effect with the optional value.
Returns an effect that models success with the specified value.
Returns a synchronous effect that does blocking and succeeds with the specified value.
The same as ZIO.succeed, but also provides access to the underlying RuntimeConfig and fiber id.
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. When no environment is required (i.e., when R == Any) it is
conceptually equivalent to flatten(effect(io))
.
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. The effect must not throw any exceptions. When no environment is
required (i.e., when R == Any) it is conceptually equivalent to
flatten(succeed(zio))
. If you wonder if the effect throws exceptions, do
not use this method, use Task.suspend or ZIO.suspend.
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. The effect must not throw any exceptions. When no environment is
required (i.e., when R == Any) it is conceptually equivalent to
flatten(succeed(zio))
. If you wonder if the effect throws exceptions, do
not use this method, use Task.suspend or ZIO.suspend.
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. When no environment is required (i.e., when R == Any) it is
conceptually equivalent to flatten(effect(io))
.
Capture ZIO trace at the current point
Transplants specified effects so that when those effects fork other effects, the forked effects will be governed by the scope of the fiber that executes this effect.
Transplants specified effects so that when those effects fork other effects, the forked effects will be governed by the scope of the fiber that executes this effect.
This can be used to "graft" deep grandchildren onto a higher-level scope, effectively extending their lifespans into the parent scope.
Prefix form of ZIO#uninterruptible
.
Makes the effect uninterruptible, but passes it a restore function that can be used to restore the inherited interruptibility from whatever region the effect is composed into.
An effect that succeeds with a unit value.
The moral equivalent of if (!p) exp
The moral equivalent of if (!p) exp
when p
has side-effects
The inverse operation IO.sandboxed
The inverse operation IO.sandboxed
Terminates with exceptions on the Left
side of the Either
error, if it
exists. Otherwise extracts the contained IO[E, A]
Returns an effect indicating that execution is no longer required to be performed on the current executor.
Returns an effect indicating that execution is no longer required to be performed on the current executor. The runtime may continue executing on this executor for efficiency but will not automatically shift back to it after completing an effect on another executor.
Updates a state in the environment with the specified function.
Feeds elements of type A
to f
and accumulates all errors in error
channel or successes in success channel.
Feeds elements of type A
to f
and accumulates all errors in error
channel or successes in success channel.
This combinator is lossy meaning that if there are errors all successes will be lost. To retain all information please use partition.
Feeds elements of type A
to f
and accumulates all errors in error
channel or successes in success channel.
Feeds elements of type A
to f
and accumulates all errors in error
channel or successes in success channel.
This combinator is lossy meaning that if there are errors all successes will be lost. To retain all information please use partition.
Feeds elements of type A
to f
and accumulates all errors, discarding
the successes.
Feeds elements of type A
to f
until it succeeds.
Feeds elements of type A
to f
until it succeeds. Returns first success
or the accumulation of all errors.
Feeds elements of type A
to f
, in parallel, until it succeeds.
Feeds elements of type A
to f
, in parallel, until it succeeds. Returns
first success or the accumulation of all errors.
In case of success all other running fibers are terminated.
Feeds elements of type A
to f
and accumulates, in parallel, all errors
in error channel or successes in success channel.
Feeds elements of type A
to f
and accumulates, in parallel, all errors
in error channel or successes in success channel.
This combinator is lossy meaning that if there are errors all successes will be lost. To retain all information please use partitionPar.
Feeds elements of type A
to f
and accumulates, in parallel, all errors
in error channel or successes in success channel.
Feeds elements of type A
to f
and accumulates, in parallel, all errors
in error channel or successes in success channel.
This combinator is lossy meaning that if there are errors all successes will be lost. To retain all information please use partitionPar.
Feeds elements of type A
to f
in parallel and accumulates all errors,
discarding the successes.
The moral equivalent of if (p) exp
Runs an effect when the supplied PartialFunction
matches for the given
value, otherwise does nothing.
Runs an effect when the supplied PartialFunction
matches for the given
effectful value, otherwise does nothing.
The moral equivalent of if (p) exp
when p
has side-effects
Locally installs a supervisor and an effect that succeeds with all the children that have been forked in the returned effect.
Runs the specified effect with the specified maximum number of fibers for parallel operators.
Runs the specified effect with an unbounded maximum number of fibers for parallel operators.
Runs the specified effect on the specified runtime configuration, restoring the old runtime configuration when it completes execution.
Returns an effect that yields to the runtime system, starting on a fresh stack.
Returns an effect that yields to the runtime system, starting on a fresh stack. Manual use of this method can improve fairness, at the cost of overhead.
Accesses the environment of the effect.
Accesses the environment of the effect.
val portNumber = effect.access(_.config.portNumber)
(Since version 2.0.0) use environmentWith
Effectfully accesses the environment of the effect.
Effectfully accesses the environment of the effect.
(Since version 2.0.0) use environmentWithZIO
Effectfully accesses the environment of the effect.
Effectfully accesses the environment of the effect.
(Since version 2.0.0) use environmentWithZIO
Uncurried version.
Uncurried version. Doesn't offer curried syntax and have worse type-inference characteristics, but guarantees no extra allocations of intermediate zio.ZIO.Acquire and zio.ZIO.Release objects.
(Since version 2.0.0) use acquireReleaseWith
When this effect represents acquisition of a resource (for example, opening
a file, launching a thread, etc.), bracket
can be used to ensure the
acquisition is not interrupted and the resource is always released.
When this effect represents acquisition of a resource (for example, opening
a file, launching a thread, etc.), bracket
can be used to ensure the
acquisition is not interrupted and the resource is always released.
The function does two things:
release
effect will not be
interrupted, and will be executed so long as this effect successfully
acquires the resource.In between acquisition and release of the resource, the use
effect is
executed.
If the release
effect fails, then the entire effect will fail even if the
use
effect succeeds. If this fail-fast behavior is not desired, errors
produced by the release
effect can be caught and ignored.
openFile("data.json").bracket(closeFile) { file => for { header <- readHeader(file) ... } yield result }
(Since version 2.0.0) use acquireReleaseWith
Uncurried version.
Uncurried version. Doesn't offer curried syntax and has worse type-inference characteristics, but guarantees no extra allocations of intermediate zio.ZIO.AcquireExit and zio.ZIO.ReleaseExit objects.
(Since version 2.0.0) use acquireReleaseExitWith
Acquires a resource, uses the resource, and then releases the resource.
Acquires a resource, uses the resource, and then releases the resource.
Neither the acquisition nor the release will be interrupted, and the
resource is guaranteed to be released, so long as the acquire
effect
succeeds. If use
fails, then after release, the returned effect will fail
with the same error.
(Since version 2.0.0) use acquireReleaseExitWith
Evaluate each effect in the structure in parallel, and collect the results.
Evaluate each effect in the structure in parallel, and collect the results.
For a sequential version, see collectAll
.
Unlike collectAllPar
, this method will use at most n
fibers.
(Since version 2.0.0) use collectAllPar
Evaluate each effect in the structure in parallel, and discard the results.
Evaluate each effect in the structure in parallel, and discard the results.
For a sequential version, see collectAllDiscard
.
Unlike collectAllParDiscard
, this method will use at most n
fibers.
(Since version 2.0.0) use collectAllParDiscard
Evaluate each effect in the structure in parallel, and discard the results.
Evaluate each effect in the structure in parallel, and discard the results.
For a sequential version, see collectAll_
.
Unlike collectAllPar_
, this method will use at most n
fibers.
(Since version 2.0.0) use collectAllParDiscard
Evaluate each effect in the structure in parallel, and discard the results.
Evaluate each effect in the structure in parallel, and discard the results.
For a sequential version, see collectAll_
.
(Since version 2.0.0) use collectAllParDiscard
Evaluate and run each effect in the structure in parallel, and collect discarding failed ones.
Evaluate and run each effect in the structure in parallel, and collect discarding failed ones.
Unlike collectAllSuccessesPar
, this method will use at most up to n
fibers.
(Since version 2.0.0) use collectAllSuccessesPar
Evaluate each effect in the structure with collectAllPar
, and collect the
results with given partial function.
Evaluate each effect in the structure with collectAllPar
, and collect the
results with given partial function.
Unlike collectAllWithPar
, this method will use at most up to n
fibers.
(Since version 2.0.0) use collectAllWithPar
Evaluate each effect in the structure from left to right, and discard the results.
Evaluate each effect in the structure from left to right, and discard the
results. For a parallel version, see collectAllPar_
.
(Since version 2.0.0) use collectAllDiscard
Evaluate each effect in the structure in parallel, collecting the the successful values and discarding the empty cases.
Evaluate each effect in the structure in parallel, collecting the the successful values and discarding the empty cases.
Unlike collectPar
, this method will use at most up to n
fibers.
(Since version 2.0.0) use collectPar
Imports a synchronous side-effect into a pure ZIO
value, translating any
thrown exceptions into typed failed effects creating with ZIO.fail
.
Imports a synchronous side-effect into a pure ZIO
value, translating any
thrown exceptions into typed failed effects creating with ZIO.fail
.
def printLine(line: String): Task[Unit] = Task.effect(println(line))
(Since version 2.0.0) use attempt
Imports an asynchronous side-effect into a pure ZIO
value.
Imports an asynchronous side-effect into a pure ZIO
value. See
effectAsyncMaybe
for the more expressive variant of this function that
can return a value synchronously.
The callback function ZIO[R, E, A] => Any
must be called at most once.
The list of fibers, that may complete the async callback, is used to provide better diagnostics.
(Since version 2.0.0) use async
Imports an asynchronous side-effect into a ZIO effect.
Imports an asynchronous side-effect into a ZIO effect. The side-effect has the option of returning the value synchronously, which is useful in cases where it cannot be determined if the effect is synchronous or asynchronous until the side-effect is actually executed. The effect also has the option of returning a canceler, which will be used by the runtime to cancel the asynchronous effect if the fiber executing the effect is interrupted.
If the register function returns a value synchronously, then the callback
function ZIO[R, E, A] => Any
must not be called. Otherwise the callback
function must be called at most once.
The list of fibers, that may complete the async callback, is used to provide better diagnostics.
(Since version 2.0.0) use asyncInterrupt
Imports an asynchronous effect into a pure ZIO
value.
Imports an asynchronous effect into a pure ZIO
value. This formulation is
necessary when the effect is itself expressed in terms of ZIO
.
(Since version 2.0.0) use asyncZIO
Imports an asynchronous effect into a pure ZIO
value, possibly returning
the value synchronously.
Imports an asynchronous effect into a pure ZIO
value, possibly returning
the value synchronously.
If the register function returns a value synchronously, then the callback
function ZIO[R, E, A] => Any
must not be called. Otherwise the callback
function must be called at most once.
The list of fibers, that may complete the async callback, is used to provide better diagnostics.
(Since version 2.0.0) use asyncMaybe
Imports a synchronous effect that does blocking IO into a pure value.
Imports a synchronous effect that does blocking IO into a pure value.
(Since version 2.0.0) use attemptBlocking
Imports a synchronous effect that does blocking IO into a pure value, with a custom cancel effect.
Imports a synchronous effect that does blocking IO into a pure value, with a custom cancel effect.
If the returned ZIO
is interrupted, the blocked thread running the
synchronous effect will be interrupted via the cancel effect.
(Since version 2.0.0) use attemptBlockingCancelable
Imports a synchronous effect that does blocking IO into a pure value,
refining the error type to java.io.IOException
.
Imports a synchronous effect that does blocking IO into a pure value,
refining the error type to java.io.IOException
.
(Since version 2.0.0) use attemptBlockingIO
Imports a synchronous effect that does blocking IO into a pure value.
Imports a synchronous effect that does blocking IO into a pure value.
If the returned ZIO
is interrupted, the blocked thread running the
synchronous effect will be interrupted via Thread.interrupt
.
Note that this adds significant overhead. For performance sensitive
applications consider using effectBlocking
or effectBlockingCancel
.
(Since version 2.0.0) use attemptBlockingInterrupt
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. When no environment is required (i.e., when R == Any) it is
conceptually equivalent to flatten(effect(io))
.
(Since version 2.0.0) use suspend
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. The effect must not throw any exceptions. When no environment is
required (i.e., when R == Any) it is conceptually equivalent to
flatten(effectTotal(zio))
. If you wonder if the effect throws exceptions,
do not use this method, use Task.effectSuspend or
ZIO.effectSuspend.
(Since version 2.0.0) use suspendSucceed
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. The effect must not throw any exceptions. When no environment is
required (i.e., when R == Any) it is conceptually equivalent to
flatten(effectTotal(zio))
. If you wonder if the effect throws exceptions,
do not use this method, use Task.effectSuspend or
ZIO.effectSuspend.
(Since version 2.0.0) use suspendSucceedWith
Returns a lazily constructed effect, whose construction may itself require effects.
Returns a lazily constructed effect, whose construction may itself require
effects. When no environment is required (i.e., when R == Any) it is
conceptually equivalent to flatten(effect(io))
.
(Since version 2.0.0) use suspendWith
Captures a synchronous computation into a lazy effect, which can be executed later and repeatedly.
Captures a synchronous computation into a lazy effect, which can be executed later and repeatedly. The synchronous computation must not throw any exceptions. If you are unsure, then don't use this method, use Task.effect, IO.effect, or ZIO.effect.
val nanoTime: UIO[Long] = IO.succeed(System.nanoTime())
(Since version 2.0.0) use succeed
The same as ZIO.effectTotal, but also provides access to the underlying RuntimeConfig and fiber id.
The same as ZIO.effectTotal, but also provides access to the underlying RuntimeConfig and fiber id.
(Since version 2.0.0) use succeedWith
Applies the function f
to each element of the Collection[A]
in
parallel, and returns the results in a new Collection[B]
.
Applies the function f
to each element of the Collection[A]
in
parallel, and returns the results in a new Collection[B]
.
Unlike foreachPar
, this method will use at most up to n
fibers.
(Since version 2.0.0) use foreachPar
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
Unlike foreachParDiscard
, this method will use at most up to n
fibers.
(Since version 2.0.0) use foreachParDiscard
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
Unlike foreachPar_
, this method will use at most up to n
fibers.
(Since version 2.0.0) use foreachParDiscard
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects in parallel, discarding the results.
For a sequential version of this method, see foreach_
.
Optimized to avoid keeping full tree of effects, so that method could be able to handle large input sequences. Behaves almost like this code:
as.foldLeft(ZIO.unit) { (acc, a) => acc.zipParLeft(f(a)) }
Additionally, interrupts all effects on any failure.
(Since version 2.0.0) use foreachParDiscard
Applies the function f
to each element of the Iterable[A]
and runs
produced effects sequentially.
Applies the function f
to each element of the Iterable[A]
and runs
produced effects sequentially.
Equivalent to foreach(as)(f).unit
, but without the cost of building the
list of results.
(Since version 2.0.0) use foreachDiscard
Returns an effect that forks all of the specified values, and returns a composite fiber that produces unit.
Returns an effect that forks all of the specified values, and returns a composite fiber that produces unit. This version is faster than forkAll in cases where the results of the forked fibers are not needed.
(Since version 2.0.0) use forkAllDiscard
Creates a ZIO
value that represents the exit value of the specified
fiber.
Creates a ZIO
value that represents the exit value of the specified
fiber.
(Since version 2.0.0) use fromFiberZIO
Lifts a function R => A
into a URIO[R, A]
.
Lifts a function R => A
into a URIO[R, A]
.
(Since version 2.0.0) use access
Lifts an effectful function whose effect requires no environment into an effect that requires the input to the function.
Lifts an effectful function whose effect requires no environment into an effect that requires the input to the function.
(Since version 2.0.0) use environmentWithZIO
Returns an effect that models failure with the specified Cause
.
Returns an effect that models failure with the specified Cause
.
(Since version 2.0.0) use failCause
Runs onTrue
if the result of b
is true
and onFalse
otherwise.
Runs onTrue
if the result of b
is true
and onFalse
otherwise.
(Since version 2.0.0) use ifZIO
Returns an effect that will execute the specified effect fully on the provided executor, before returning to the default executor.
Returns an effect that will execute the specified effect fully on the provided executor, before returning to the default executor. See ZIO!.lock.
(Since version 2.0.0) use onExecutor
Loops with the specified effectual function purely for its effects.
Loops with the specified effectual function purely for its effects. The moral equivalent of:
var s = initial while (cont(s)) { body(s) s = inc(s) }
(Since version 2.0.0) use loopDiscard
Sequentially zips the specified effects using the specified combiner function.
Sequentially zips the specified effects using the specified combiner function.
(Since version 2.0.0) use zip
Sequentially zips the specified effects using the specified combiner function.
Sequentially zips the specified effects using the specified combiner function.
(Since version 2.0.0) use zip
Sequentially zips the specified effects using the specified combiner function.
Sequentially zips the specified effects using the specified combiner function.
(Since version 2.0.0) use zip
Returns an effect that executes the specified effects in parallel,
combining their results with the specified f
function.
Returns an effect that executes the specified effects in parallel,
combining their results with the specified f
function. If any effect
fails, then the other effects will be interrupted.
(Since version 2.0.0) use zipPar
Returns an effect that executes the specified effects in parallel,
combining their results with the specified f
function.
Returns an effect that executes the specified effects in parallel,
combining their results with the specified f
function. If any effect
fails, then the other effects will be interrupted.
(Since version 2.0.0) use zipPar
Returns an effect that executes the specified effects in parallel,
combining their results with the specified f
function.
Returns an effect that executes the specified effects in parallel,
combining their results with the specified f
function. If any effect
fails, then the other effects will be interrupted.
(Since version 2.0.0) use zipPar
Merges an Iterable[IO]
to a single IO, working in with up to n
fibers
in parallel.
Merges an Iterable[IO]
to a single IO, working in with up to n
fibers
in parallel.
Due to the parallel nature of this combinator, f
must be both:
f(a, b) == f(b, a)
f(a, f(b, c)) == f(f(a, b), c)
It's unsafe to execute side effects inside f
, as f
may be executed more
than once for some of in
elements during effect execution.
(Since version 2.0.0) use mergeAllPar
Feeds elements of type A
to a function f
that returns an effect.
Feeds elements of type A
to a function f
that returns an effect.
Collects all successes and failures in parallel and returns the result as a
tuple.
Unlike partitionPar, this method will use at most up to n
fibers.
(Since version 2.0.0) use partitionPar
Reduces an Iterable[IO]
to a single IO
, working in up to n
fibers in
parallel.
Reduces an Iterable[IO]
to a single IO
, working in up to n
fibers in
parallel.
(Since version 2.0.0) use reduceAllPar
Performs this effect the specified number of times and collects the results.
Performs this effect the specified number of times and collects the results.
(Since version 2.0.0) use replicateZIO
Performs this effect the specified number of times, discarding the results.
Performs this effect the specified number of times, discarding the results.
(Since version 2.0.0) use replicateZIODiscard
Requires that the given ZIO[R, E, Option[A]]
contain a value.
Requires that the given ZIO[R, E, Option[A]]
contain a value. If there is
no value, then the specified error will be raised.
(Since version 2.0.0) use someOrFail
Accesses the specified services in the environment of the effect.
Accesses the specified services in the environment of the effect.
(Since version 2.0.0) use service
Accesses the specified services in the environment of the effect.
Accesses the specified services in the environment of the effect.
(Since version 2.0.0) use service
Accesses the specified services in the environment of the effect.
Accesses the specified services in the environment of the effect.
(Since version 2.0.0) use service
Sequentially zips the specified effects.
Sequentially zips the specified effects. Specialized version of mapN.
(Since version 2.0.0) use zip
Sequentially zips the specified effects.
Sequentially zips the specified effects. Specialized version of mapN.
(Since version 2.0.0) use zip
Sequentially zips the specified effects.
Sequentially zips the specified effects. Specialized version of mapN.
(Since version 2.0.0) use zip
Zips the specified effects in parallel.
Zips the specified effects in parallel. Specialized version of mapParN.
(Since version 2.0.0) use zipPar
Zips the specified effects in parallel.
Zips the specified effects in parallel. Specialized version of mapParN.
(Since version 2.0.0) use zipPar
Zips the specified effects in parallel.
Zips the specified effects in parallel. Specialized version of mapParN.
(Since version 2.0.0) use zipPar
The moral equivalent of if (!p) exp
when p
has side-effects
The moral equivalent of if (!p) exp
when p
has side-effects
(Since version 2.0.0) use unlessZIO
Feeds elements of type A
to f
in parallel and accumulates all errors,
discarding the successes.
Feeds elements of type A
to f
in parallel and accumulates all errors,
discarding the successes.
(Since version 2.0.0) use validateParDiscard
Feeds elements of type A
to f
and accumulates all errors, discarding
the successes.
Feeds elements of type A
to f
and accumulates all errors, discarding
the successes.
(Since version 2.0.0) use validateDiscard
Runs an effect when the supplied PartialFunction
matches for the given
effectful value, otherwise does nothing.
Runs an effect when the supplied PartialFunction
matches for the given
effectful value, otherwise does nothing.
(Since version 2.0.0) use whenCaseZIO
The moral equivalent of if (p) exp
when p
has side-effects
The moral equivalent of if (p) exp
when p
has side-effects
(Since version 2.0.0) use whenZIO