ZLayer

zio.ZLayer
See theZLayer companion object
sealed abstract class ZLayer[-RIn, +E, +ROut]

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.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
ZLayer[RIn, E, ROut]

Members list

Value members

Concrete methods

final def !(implicit ev1: E <:< Throwable, ev2: CanFail[E], trace: Trace): ZLayer[RIn, Nothing, ROut]

A symbolic alias for orDie.

A symbolic alias for orDie.

Attributes

final def +!+[E1 >: E, RIn2, ROut1 >: ROut, ROut2](that: => ZLayer[RIn2, E1, ROut2]): ZLayer[RIn & RIn2, E1, ROut1 & ROut2]
final def ++[E1 >: E, RIn2, ROut1 >: ROut, ROut2](that: => ZLayer[RIn2, E1, ROut2])(implicit tag: Tag[ROut2]): ZLayer[RIn & RIn2, E1, ROut1 & ROut2]

Combines this layer with the specified layer, producing a new layer that has the inputs and outputs of = both.

Combines this layer with the specified layer, producing a new layer that has the inputs and outputs of = both.

Attributes

def <>[RIn1 <: RIn, E1, ROut1 >: ROut](that: => ZLayer[RIn1, E1, ROut1])(implicit ev: CanFail[E], trace: Trace): ZLayer[RIn1, E1, ROut1]

A symbolic alias for orElse.

A symbolic alias for orElse.

Attributes

def >+>[RIn2, E1 >: E, ROut2](that: => ZLayer[ROut & RIn2, E1, ROut2])(implicit tagged: Tag[ROut], tagged2: Tag[ROut2], trace: Trace): ZLayer[RIn & RIn2, E1, ROut & ROut2]
Implicitly added by ZLayerProvideSomeOps

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer, and the outputs of both layers.

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer, and the outputs of both layers.

Attributes

def >+>[E1 >: E, RIn2 >: ROut, ROut1 >: ROut, ROut2](that: => ZLayer[RIn2, E1, ROut2])(implicit tagged: Tag[ROut2], trace: Trace): ZLayer[RIn, E1, ROut1 & ROut2]
Implicitly added by ZLayerProvideSomeOps

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer, and the outputs of both layers.

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer, and the outputs of both layers.

Attributes

def >>>[RIn2, E1 >: E, ROut2](that: => ZLayer[ROut & RIn2, E1, ROut2])(implicit tag: Tag[ROut], trace: Trace): ZLayer[RIn & RIn2, E1, ROut2]
Implicitly added by ZLayerProvideSomeOps

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer as well as any leftover inputs, and the outputs of the specified layer.

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer as well as any leftover inputs, and the outputs of the specified layer.

Attributes

def >>>[E1 >: E, ROut2](that: => ZLayer[ROut, E1, ROut2])(implicit trace: Trace): ZLayer[RIn, E1, ROut2]
Implicitly added by ZLayerProvideSomeOps

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer as well as any leftover inputs, and the outputs of the specified layer.

Feeds the output services of this layer into the input of the specified layer, resulting in a new layer with the inputs of this layer as well as any leftover inputs, and the outputs of the specified layer.

Attributes

final def and[E1 >: E, RIn2, ROut1 >: ROut, ROut2](that: => ZLayer[RIn2, E1, ROut2])(implicit tag: Tag[ROut2]): ZLayer[RIn & RIn2, E1, ROut1 & ROut2]

A named alias for ++.

A named alias for ++.

Attributes

final def andTo[E1 >: E, RIn2 >: ROut, ROut1 >: ROut, ROut2](that: => ZLayer[RIn2, E1, ROut2])(implicit tagged: Tag[ROut2], trace: Trace): ZLayer[RIn, E1, ROut1 & ROut2]

A named alias for >+>.

A named alias for >+>.

Attributes

final def apply[R, E1 >: E, A](zio: ZIO[ROut & R, E1, A])(implicit ev1: Tag[R], ev2: Tag[ROut], ev3: Tag[RIn], trace: Trace): ZIO[RIn & R, E1, A]
Implicitly added by ZLayerProvideSomeOps

Provides an effect with part of its required environment, eliminating its dependency on the services output by this layer.

Provides an effect with part of its required environment, eliminating its dependency on the services output by this layer.

Attributes

final def build(implicit trace: Trace): ZIO[RIn & Scope, E, ZEnvironment[ROut]]

Builds a layer into a scoped value.

Builds a layer into a scoped value.

Attributes

final def build(scope: => Scope)(implicit trace: Trace): ZIO[RIn, E, ZEnvironment[ROut]]

Builds a layer into a ZIO value. Any resources associated with this layer will be released when the specified scope is closed unless their scope has been extended. This allows building layers where the lifetime of some of the services output by the layer exceed the lifetime of the effect the layer is provided to.

Builds a layer into a ZIO value. Any resources associated with this layer will be released when the specified scope is closed unless their scope has been extended. This allows building layers where the lifetime of some of the services output by the layer exceed the lifetime of the effect the layer is provided to.

Attributes

final def catchAll[RIn1 <: RIn, E1, ROut1 >: ROut](handler: E => ZLayer[RIn1, E1, ROut1])(implicit trace: Trace): ZLayer[RIn1, E1, ROut1]

Recovers from all errors.

Recovers from all errors.

Attributes

final def catchAllCause[RIn1 <: RIn, E1, ROut1 >: ROut](handler: Cause[E] => ZLayer[RIn1, E1, ROut1])(implicit trace: Trace): ZLayer[RIn1, E1, ROut1]

Recovers from all errors.

Recovers from all errors.

Attributes

final def debug(implicit trace: Trace): ZLayer[RIn, E, ROut]

Taps the layer, printing the result of calling .toString on the value.

Taps the layer, printing the result of calling .toString on the value.

Attributes

final def debug(prefix: => String)(implicit trace: Trace): ZLayer[RIn, E, ROut]

Taps the layer, printing the result of calling .toString on the value. Prefixes the output with the given message.

Taps the layer, printing the result of calling .toString on the value. Prefixes the output with the given message.

Attributes

final def extendScope: ZLayer[RIn & Scope, E, ROut]

Extends the scope of this layer, returning a new layer that when provided to an effect will not immediately release its associated resources when that effect completes execution but instead when the scope the resulting effect depends on is closed.

Extends the scope of this layer, returning a new layer that when provided to an effect will not immediately release its associated resources when that effect completes execution but instead when the scope the resulting effect depends on is closed.

Attributes

final def flatMap[RIn1 <: RIn, E1 >: E, ROut2](f: ZEnvironment[ROut] => ZLayer[RIn1, E1, ROut2])(implicit trace: Trace): ZLayer[RIn1, E1, ROut2]

Constructs a layer dynamically based on the output of this layer.

Constructs a layer dynamically based on the output of this layer.

Attributes

final def flatten[RIn1 <: RIn, E1 >: E, ROut1 >: ROut, ROut2](implicit tag: Tag[ROut1], ev1: ROut1 <:< ZLayer[RIn1, E1, ROut2], trace: Trace): ZLayer[RIn1, E1, ROut2]

Returns a layer that performs the outer layer first, followed by the inner layer, yielding the value of the inner layer.

Returns a layer that performs the outer layer first, followed by the inner layer, yielding the value of the inner layer.

This method can be used to "flatten" nested layers.

Attributes

final def foldCauseLayer[E1, RIn1 <: RIn, ROut2](failure: Cause[E] => ZLayer[RIn1, E1, ROut2], success: ZEnvironment[ROut] => ZLayer[RIn1, E1, ROut2])(implicit ev: CanFail[E]): ZLayer[RIn1, E1, ROut2]

Feeds the error or output services of this layer into the input of either the specified failure or success layers, resulting in a new layer with the inputs of this layer, and the error or outputs of the specified layer.

Feeds the error or output services of this layer into the input of either the specified failure or success layers, resulting in a new layer with the inputs of this layer, and the error or outputs of the specified layer.

Attributes

final def foldLayer[E1, RIn1 <: RIn, ROut2](failure: E => ZLayer[RIn1, E1, ROut2], success: ZEnvironment[ROut] => ZLayer[RIn1, E1, ROut2])(implicit ev: CanFail[E], trace: Trace): ZLayer[RIn1, E1, ROut2]

Feeds the error or output services of this layer into the input of either the specified failure or success layers, resulting in a new layer with the inputs of this layer, and the error or outputs of the specified layer.

Feeds the error or output services of this layer into the input of either the specified failure or success layers, resulting in a new layer with the inputs of this layer, and the error or outputs of the specified layer.

Attributes

final def fresh: ZLayer[RIn, E, ROut]

Creates a fresh version of this layer that will not be shared.

Creates a fresh version of this layer that will not be shared.

Attributes

final def launch(implicit trace: Trace): ZIO[RIn, E, Nothing]

Builds this layer and uses it until it is interrupted. This is useful when your entire application is a layer, such as an HTTP server.

Builds this layer and uses it until it is interrupted. This is useful when your entire application is a layer, such as an HTTP server.

Attributes

final def map[ROut1](f: ZEnvironment[ROut] => ZEnvironment[ROut1])(implicit trace: Trace): ZLayer[RIn, E, ROut1]

Returns a new layer whose output is mapped by the specified function.

Returns a new layer whose output is mapped by the specified function.

Attributes

final def mapError[E1](f: E => E1)(implicit ev: CanFail[E], trace: Trace): ZLayer[RIn, E1, ROut]

Returns a layer with its error channel mapped using the specified function.

Returns a layer with its error channel mapped using the specified function.

Attributes

final def mapErrorCause[E2](h: Cause[E] => Cause[E2])(implicit trace: Trace): ZLayer[RIn, E2, ROut]

Returns a layer with its full cause of failure mapped using the specified function. This can be used to transform errors while preserving the original structure of Cause.

Returns a layer with its full cause of failure mapped using the specified function. This can be used to transform errors while preserving the original structure of Cause.

Attributes

See also
final def memoize(implicit trace: Trace): ZIO[Scope, Nothing, ZLayer[RIn, E, ROut]]

Returns a scoped effect that, if evaluated, will return the lazily computed result of this layer.

Returns a scoped effect that, if evaluated, will return the lazily computed result of this layer.

Attributes

final def orDie(implicit ev1: IsSubtypeOfError[E, Throwable], ev2: CanFail[E], trace: Trace): ZLayer[RIn, Nothing, ROut]

Translates effect failure into death of the fiber, making all failures unchecked and not a part of the type of the layer.

Translates effect failure into death of the fiber, making all failures unchecked and not a part of the type of the layer.

Attributes

final def orElse[RIn1 <: RIn, E1, ROut1 >: ROut](that: => ZLayer[RIn1, E1, ROut1])(implicit ev: CanFail[E], trace: Trace): ZLayer[RIn1, E1, ROut1]

Executes this layer and returns its output, if it succeeds, but otherwise executes the specified layer.

Executes this layer and returns its output, if it succeeds, but otherwise executes the specified layer.

Attributes

def passthrough(implicit in: Tag[RIn], out: Tag[ROut], trace: Trace): ZLayer[RIn, E, RIn & ROut]
Implicitly added by ZLayerInvariantOps

Returns a new layer that produces the outputs of this layer but also passes through the inputs.

Returns a new layer that produces the outputs of this layer but also passes through the inputs.

Attributes

def project[ROut2 : Tag](f: ROut => ROut2)(implicit evidence$293: Tag[ROut2], tag: Tag[ROut], trace: Trace): ZLayer[RIn, E, ROut2]
Implicitly added by ZLayerInvariantOps

Projects out part of one of the services output by this layer using the specified function.

Projects out part of one of the services output by this layer using the specified function.

Attributes

def reloadableAuto(schedule: Schedule[RIn, Any, Any])(implicit tagOut: Tag[ROut], trace: Trace): ZLayer[RIn, E, Reloadable[ROut]]
Implicitly added by ZLayerInvariantOps

Returns a layer that produces a reloadable version of this service.

Returns a layer that produces a reloadable version of this service.

Attributes

def reloadableAutoFromConfig[RIn2](scheduleFromConfig: ZEnvironment[RIn2] => Schedule[RIn & RIn2, Any, Any])(implicit tagOut: Tag[ROut], trace: Trace): ZLayer[RIn & RIn2, E, Reloadable[ROut]]
Implicitly added by ZLayerInvariantOps

Returns a layer that produces a reloadable version of this service, where the reloading schedule is derived from the layer input.

Returns a layer that produces a reloadable version of this service, where the reloading schedule is derived from the layer input.

Attributes

def reloadableManual(implicit tagOut: Tag[ROut], trace: Trace): ZLayer[RIn, E, Reloadable[ROut]]
Implicitly added by ZLayerInvariantOps

Returns a layer that produces a reloadable version of this service.

Returns a layer that produces a reloadable version of this service.

Attributes

final def retry[RIn1 <: RIn](schedule0: => Schedule[RIn1, E, Any])(implicit trace: Trace): ZLayer[RIn1, E, ROut]

Retries constructing this layer according to the specified schedule.

Retries constructing this layer according to the specified schedule.

Attributes

final def tap[RIn1 <: RIn, E1 >: E](f: ZEnvironment[ROut] => ZIO[RIn1, E1, Any])(implicit trace: Trace): ZLayer[RIn1, E1, ROut]

Performs the specified effect if this layer succeeds.

Performs the specified effect if this layer succeeds.

Attributes

final def tapError[RIn1 <: RIn, E1 >: E](f: E => ZIO[RIn1, E1, Any])(implicit trace: Trace): ZLayer[RIn1, E1, ROut]

Performs the specified effect if this layer fails.

Performs the specified effect if this layer fails.

Attributes

final def tapErrorCause[RIn1 <: RIn, E1 >: E](f: Cause[E] => ZIO[RIn1, E1, Any])(implicit trace: Trace): ZLayer[RIn1, E1, ROut]

Performs the specified effect if this layer fails.

Performs the specified effect if this layer fails.

Attributes

final def to[E1 >: E, ROut2](that: => ZLayer[ROut, E1, ROut2])(implicit trace: Trace): ZLayer[RIn, E1, ROut2]

A named alias for >>>.

A named alias for >>>.

Attributes

final def toRuntime(implicit ev: Any <:< RIn, trace: Trace): ZIO[Scope, E, Runtime[ROut]]

Converts a layer that requires no services into a scoped runtime, which can be used to execute effects.

Converts a layer that requires no services into a scoped runtime, which can be used to execute effects.

Attributes

def unit(implicit trace: Trace): ZLayer[RIn, E, Unit]

Replaces the layer's output with Unit.

Replaces the layer's output with Unit.

When used with ZIO.provide and ZLayer.make macros (and their variants), this will suppress the unused layer warning that is normally emitted, and will actually include the layer for its side-effects.

Attributes

final def update[A >: ROut : Tag](f: A => A)(implicit evidence$292: Tag[A], trace: Trace): ZLayer[RIn, E, ROut]

Updates one of the services output by this layer.

Updates one of the services output by this layer.

Attributes

final def zipWithPar[E1 >: E, RIn2, ROut1 >: ROut, ROut2, ROut3](that: => ZLayer[RIn2, E1, ROut2])(f: (ZEnvironment[ROut], ZEnvironment[ROut2]) => ZEnvironment[ROut3]): ZLayer[RIn & RIn2, E1, ROut3]

Combines this layer the specified layer, producing a new layer that has the inputs of both, and the outputs of both combined using the specified function.

Combines this layer the specified layer, producing a new layer that has the inputs of both, and the outputs of both combined using the specified function.

Attributes

Concrete fields

final lazy override val hashCode: Int

Returns the hash code of this layer.

Returns the hash code of this layer.

Attributes