<A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<
A,
E | E1,
R1 | Exclude<R, Scope.Scope>
>Unwraps a Layer from an Effect, flattening the nested structure.
When to use
Use when you have an Effect that produces a Layer and you want to
use that layer directly.
Details
The resulting Layer will have the combined error and dependency types from both the outer Effect and the inner Layer.
Example (Unwrapping an effectful layer)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layerEffect = Effect.succeed(
Layer.succeed(Database, { query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result")) })
)
const unwrappedLayer = Layer.unwrap(layerEffect)export const const unwrap: <A, E1, R1, E, R>(
self: Effect<Layer<A, E1, R1>, E, R>
) => Layer<
A,
E | E1,
R1 | Exclude<R, Scope.Scope>
>
Unwraps a Layer from an Effect, flattening the nested structure.
When to use
Use when you have an Effect that produces a Layer and you want to
use that layer directly.
Details
The resulting Layer will have the combined error and dependency types from
both the outer Effect and the inner Layer.
Example (Unwrapping an effectful layer)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layerEffect = Effect.succeed(
Layer.succeed(Database, { query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result")) })
)
const unwrappedLayer = Layer.unwrap(layerEffect)
unwrap = <function (type parameter) A in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>A, function (type parameter) E1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E1, function (type parameter) R1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R1, function (type parameter) E in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E, function (type parameter) R in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R>(
self: Effect<Layer<A, E1, R1>, E, R>(parameter) self: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: import EffectEffect<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<function (type parameter) A in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>A, function (type parameter) E1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E1, function (type parameter) R1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R1>, function (type parameter) E in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E, function (type parameter) R in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R>
): 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<function (type parameter) A in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>A, function (type parameter) E in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E | function (type parameter) E1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E1, function (type parameter) R1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R1 | type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R, import ScopeScope.Scope>> => {
const const service: Context.Service<
Layer<A, E1, R1>,
Layer<A, E1, R1>
>
const service: {
key: string;
Service: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<A>, E1, R1>;
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; <…;
};
of: (this: void, self: Layer<A, E1, R1>) => Layer<A, E1, R1>;
context: (self: Layer<A, E1, R1>) => Context.Context<Layer<A, E1, R1>>;
use: (f: (service: Layer<A, E1, R1>) => Effect<A, E, R>) => Effect<A, E, Layer<A, E1, R1> | R>;
useSync: (f: (service: Layer<A, E1, R1>) => A) => Effect<A, never, Layer<A, E1, R1>>;
Identifier: Identifier;
stack: string | undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
service = import ContextContext.Service<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<function (type parameter) A in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>A, function (type parameter) E1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>E1, function (type parameter) R1 in <A, E1, R1, E, R>(self: Effect<Layer<A, E1, R1>, E, R>): Layer<A, E | E1, R1 | Exclude<R, Scope.Scope>>R1>>("effect/Layer/unwrap")
return const flatMap: {
<A, A2, E2, R2>(
f: (
context: Context.Context<A>
) => Layer<A2, E2, R2>
): <E, R>(
self: Layer<A, E, R>
) => Layer<A2, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Layer<A, E, R>,
f: (
context: Context.Context<A>
) => Layer<A2, E2, R2>
): Layer<A2, E | E2, R | R2>
}
flatMap(const effect: {
<I, S>(service: Context.Key<I, S>): <E, R>(
effect: Effect<S, E, R>
) => Layer<I, E, Exclude<R, Scope.Scope>>
<I, S, E, R>(
service: Context.Key<I, S>,
effect: Effect<Types.NoInfer<S>, E, R>
): Layer<I, E, Exclude<R, Scope.Scope>>
}
effect(const service: Context.Service<
Layer<A, E1, R1>,
Layer<A, E1, R1>
>
const service: {
key: string;
Service: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<A>, E1, R1>;
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; <…;
};
of: (this: void, self: Layer<A, E1, R1>) => Layer<A, E1, R1>;
context: (self: Layer<A, E1, R1>) => Context.Context<Layer<A, E1, R1>>;
use: (f: (service: Layer<A, E1, R1>) => Effect<A, E, R>) => Effect<A, E, Layer<A, E1, R1> | R>;
useSync: (f: (service: Layer<A, E1, R1>) => A) => Effect<A, never, Layer<A, E1, R1>>;
Identifier: Identifier;
stack: string | undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
service)(self: Effect<Layer<A, E1, R1>, E, R>(parameter) self: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self), import ContextContext.get(const service: Context.Service<
Layer<A, E1, R1>,
Layer<A, E1, R1>
>
const service: {
key: string;
Service: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<A>, E1, R1>;
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; <…;
};
of: (this: void, self: Layer<A, E1, R1>) => Layer<A, E1, R1>;
context: (self: Layer<A, E1, R1>) => Context.Context<Layer<A, E1, R1>>;
use: (f: (service: Layer<A, E1, R1>) => Effect<A, E, R>) => Effect<A, E, Layer<A, E1, R1> | R>;
useSync: (f: (service: Layer<A, E1, R1>) => A) => Effect<A, never, Layer<A, E1, R1>>;
Identifier: Identifier;
stack: string | undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
service))
}