Layer<never, never, never>An empty layer that provides no services, cannot fail, has no requirements, and performs no construction or finalization work.
When to use
Use as the no-op branch when conditionally composing layers.
Example (Disabling optional lifecycle work)
import { Console, Layer } from "effect"
declare const flag: boolean
const StartupLogLive = flag
? Layer.effectDiscard(Console.log("application starting"))
: Layer.emptyexport const const empty: Layer<never>const empty: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<never>, never, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
An empty layer that provides no services, cannot fail, has no requirements,
and performs no construction or finalization work.
When to use
Use as the no-op branch when conditionally composing layers.
Example (Disabling optional lifecycle work)
import { Console, Layer } from "effect"
declare const flag: boolean
const StartupLogLive = flag
? Layer.effectDiscard(Console.log("application starting"))
: Layer.empty
empty: interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<never> = const succeedContext: <A>(
context: Context.Context<A>
) => Layer<A>
Constructs a layer that provides all services in an already available
Context.
When to use
Use when you need a Layer built from an existing Context, including when
you need to provide multiple services at once.
Details
This is a more general version of succeed that allows you to provide
multiple services at once through a Context.
Example (Providing multiple services from a context)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
class Logger extends Context.Service<Logger, {
readonly log: (msg: string) => Effect.Effect<void>
}>()("Logger") {}
const context = Context.make(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result"))
}).pipe(
Context.add(Logger, {
log: (msg: string) => Effect.sync(() => console.log(msg))
})
)
const layer = Layer.succeedContext(context)
succeedContext(import ContextContext.empty())