Returns an effectful function that extracts out the first element of a tuple.
Returns an effectful function that extracts out the first element of a tuple.
Returns an effectful function that extracts out the second element of a tuple.
Returns an effectful function that extracts out the second element of a tuple.
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
.
Accesses the environment of the effect.
Accesses the environment of the effect.
val portNumber = effect.access(_.config.portNumber)
Effectfully accesses the environment of the effect.
Effectfully accesses the environment of the effect.
Makes an explicit check to see if the fiber has been interrupted, and if so, performs self-interruption
Makes an explicit check to see if the fiber has been interrupted, and if so, performs self-interruption
Uncurried version.
Uncurried version. Doesn't offer curried syntax and have worse type-inference characteristics, but guarantees no extra allocations of intermediate zio.ZIO.BracketAcquire and zio.ZIO.BracketRelease objects.
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:
1. Ensures this effect, which acquires the resource, will not be
interrupted. Of course, acquisition may fail for internal reasons (an
uncaught exception).
2. Ensures the 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 }
Uncurried version.
Uncurried version. Doesn't offer curried syntax and have worse type-inference characteristics, but guarantees no extra allocations of intermediate zio.ZIO.BracketExitAcquire and zio.ZIO.BracketExitRelease 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.
Checks the interrupt status, and produces the effect returned by the specified callback.
Checks the interrupt status, and produces the effect returned by the specified callback.
Checks supervision status.
Checks supervision status.
Checks the ZIO Tracing status, and produces the effect returned by the specified callback.
Checks the ZIO Tracing status, and produces the effect returned by the specified callback.
Provides access to the list of child fibers supervised by this fiber.
Provides access to the list of child fibers supervised by this fiber.
Note: supervision must be enabled (via ZIO#supervised) on the current fiber for this operation to return non-empty lists.
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 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
.
Unlike collectAllPar
, this method will use at most n
fibers.
Evaluate and run each effect in the structure and collect discarding failed ones.
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 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.
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.
Evaluate each effect in the structure with collectAll
, and collect
the results with given partial function.
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.
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.
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.
Returns information about the current fiber, such as its identity.
Returns information about the current fiber, such as its identity.
Constructs an effect based on 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.
Returns an effect from a zio.Exit value.
Imports a synchronous effect into a pure ZIO
value, translating any
throwables into a Throwable
failure in the returned value.
Imports a synchronous effect into a pure ZIO
value, translating any
throwables into a Throwable
failure in the returned value.
def putStrLn(line: String): Task[Unit] = Task.effect(println(line))
Imports an asynchronous effect into a pure ZIO
value.
Imports an asynchronous 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] => Unit
must be called at most once.
Imports an asynchronous effect into a pure IO
value.
Imports an asynchronous effect into a pure IO
value. The 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 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] => Unit
must not be called. Otherwise the callback
function must be called at most once.
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 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.
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(effectTotal(zio))
. If you wonder if the effect throws exceptions,
do not use this method, use Task.effectSuspend or ZIO.effectSuspend.
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.
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))
.
Imports a total synchronous effect into a pure ZIO
value.
Imports a total synchronous effect into a pure ZIO
value.
The effect must not throw any exceptions. If you wonder if the effect
throws exceptions, then do not use this method, use Task.effect,
IO.effect, or ZIO.effect.
val nanoTime: UIO[Long] = IO.effectTotal(System.nanoTime())
Accesses the whole environment of the effect.
Accesses the whole environment of the effect.
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 races this effect with all the specified effects, yielding the value of the first effect to succeed with a value.
Returns an effect that races this effect with all the specified effects, yielding the value of the first effect to succeed with a value. Losers of the race will be interrupted immediately
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.
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 effectful function f
, working sequentially.
Folds an Iterable[A]
using an effectful function f
, working sequentially.
Applies the function f
to each element of the Iterable[A]
and
returns the results in a new List[B]
.
Applies the function f
to each element of the Iterable[A]
and
returns the results in a new List[B]
.
For a parallel version of this method, see foreachPar
.
Applies the function f
to each element of the Iterable[A]
in parallel,
and returns the results in a new List[B]
.
Applies the function f
to each element of the Iterable[A]
in parallel,
and returns the results in a new List[B]
.
For a sequential version of this method, see foreach
.
Applies the function f
to each element of the Iterable[A]
in parallel,
and returns the results in a new List[B]
.
Applies the function f
to each element of the Iterable[A]
in parallel,
and returns the results in a new List[B]
.
Unlike foreachPar
, this method will use at most up to n
fibers.
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.
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_
.
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).void
, but without the cost of building
the list of results.
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 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.
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.
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.
Lifts a function R => A
into a ZIO[R, Nothing, A]
.
Lifts a function R => A
into a ZIO[R, Nothing, A]
.
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.
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
.
Lifts an Option
into a ZIO
.
Lifts an Option
into a ZIO
.
Lifts a Try
into a ZIO
.
Lifts a Try
into a ZIO
.
Returns an effect that models failure with the specified Cause
.
Returns an effect that models failure with the specified Cause
.
Returns an effect that models failure with the specified Cause
.
Returns an effect that models failure with the specified Cause
.
This version takes in a lazily-evaluated trace that can be attached to the Cause
via Cause.Traced
.
Returns an effect that supervises the specified effect, ensuring that all fibers that it forks are passed to the specified supervisor as soon as the supervised effect completes.
Returns an effect that supervises the specified effect, ensuring that all fibers that it forks are passed to the specified supervisor as soon as the supervised effect completes.
Returns the identity effectful function, which performs no effects
Returns the identity effectful function, which performs no effects
Returns an effect that is interrupted.
Returns an effect that is interrupted.
Returns a new effect that ensures that any fibers that are forked by the effect are interrupted when this effect completes.
Returns a new effect that ensures that any fibers that are forked by the effect are interrupted when this effect completes.
Prefix form of ZIO#interruptible
.
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.
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.
Returns an effect with the value on the left part.
Returns an effect with the value on the left part.
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.
Merges an Iterable[IO]
to a single IO, working sequentially.
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.
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.
Returns an effect with the empty value.
Returns an effect with the empty value.
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 sequentially.
Reduces an Iterable[IO]
to a single IO
, working in parallel.
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 return.
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.
Acquires a resource, uses the resource, and then releases the resource.
Acquires a resource, uses the resource, and then releases the resource.
However, unlike bracket
, 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 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 non-functional code that must call back into functional code.
Alias for ZIO.collectAll
Alias for ZIO.collectAll
Alias for ZIO.collectAllPar
Alias for ZIO.collectAllPar
Alias for ZIO.collectAllParN
Alias for ZIO.collectAllParN
Sleeps for the specified duration.
Sleeps for the specified duration. This method is asynchronous, and does not actually block the fiber.
Returns an effect with the optional value.
Returns an effect with the optional value.
Returns an effect that models success with the specified strictly- evaluated value.
Returns an effect that models success with the specified strictly- evaluated value.
Returns a new effect that has the same effects as this one, but with the supervision status changed as specified.
Returns a new effect that has the same effects as this one, but with the supervision status changed as specified.
Enables supervision for this effect.
Enables supervision for this effect. This will cause fibers forked by this effect to be tracked and will enable their inspection via ZIO.children.
Returns an effectful function that merely swaps the elements in a Tuple2
.
Returns an effectful function that merely swaps the elements in a Tuple2
.
Capture ZIO trace at the current point
Capture ZIO trace at the current point
Prefix form of ZIO#traced
.
Prefix form of ZIO#traced
.
Alias for ZIO.foreach
Alias for ZIO.foreach
Alias for ZIO.foreachPar
Alias for ZIO.foreachPar
Alias for ZIO.foreachParN
Alias for ZIO.foreachParN
Alias for ZIO.foreachParN_
Alias for ZIO.foreachParN_
Alias for ZIO.foreachPar_
Alias for ZIO.foreachPar_
Alias for ZIO.foreach_
Alias for ZIO.foreach_
Prefix form of ZIO#uninterruptible
.
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.
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.
Strictly-evaluated unit lifted into the ZIO
monad.
Strictly-evaluated unit lifted into the ZIO
monad.
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]
Disables supervision for this effect.
Disables supervision for this effect. This will cause fibers forked by this effect to not be tracked or appear in the list returned by ZIO.children.
Prefix form of ZIO#untraced
.
Prefix form of ZIO#untraced
.
The moral equivalent of if (p) exp
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 value, otherwise does nothing.
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.
The moral equivalent of if (p) exp
when p
has side-effects
The moral equivalent of if (p) exp
when p
has side-effects
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.
(Since version 1.0.0) use effectTotal
(Since version 1.0.0) use effectSuspendTotal
(Since version 1.0.0) use effectSuspendTotalWith