<T extends object>(
resourceId: string,
patch: ConfigPatch<T>
): Layer.Layer<never>Layer that appends one configure patch for resourceId.
Provide or merge with the resource .layer so patches are visible when that layer builds.
export const const configureLayer: <T extends object>(
resourceId: string,
patch: ConfigPatch<T>
) => Layer.Layer<never>
Layer that appends one configure patch for resourceId.
Provide or merge with the resource .layer so patches are visible when that layer builds.
configureLayer = <function (type parameter) T in <T extends object>(resourceId: string, patch: ConfigPatch<T>): Layer.Layer<never>T extends object>(
resourceId: stringresourceId: string,
patch: ConfigPatch<T>patch: type ConfigPatch<T> =
| PartialConfigPatch<T>
| ((previous: T) => T)
Patch for a resource or process spec.
- Partial object — shallow-merge fields; use a function value to replace a field.
effect field — a unary function (previous) => next updates the prior worker /
supervised body; a multi-argument function value replaces effect outright (queue workers
stay two-argument).
- Full reducer —
(previous) => next over the whole spec (see
configureLayer
).
ConfigPatch<function (type parameter) T in <T extends object>(resourceId: string, patch: ConfigPatch<T>): Layer.Layer<never>T>,
): import LayerLayer.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 const tag: Context.ServiceClass<
never,
string,
ReadonlyArray<ConfigPatch<T>>
>
const tag: {
key: Identifier;
Service: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<ConfigPatch<T>>>): Array<ConfigPatch<T>>; (...items: Array<ConfigPatch<T> | ConcatArray<ConfigPatch<T>>>): Array<ConfigPatch<T>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<ConfigPatch<T>>;
indexOf: (searchElement: ConfigPatch<T>, fromIndex?: number) => number;
lastIndexOf: (searchElement: ConfigPatch<T>, fromIndex?: number) => number;
every: { (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unk…;
some: (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, thisAr…;
reduce: { (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigPatch<T>, currentIndex: number, array: ReadonlyArray<ConfigPatch<T>>) => ConfigPatch<T>): ConfigPatch<T>; (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigP…;
reduceRight: { (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigPatch<T>, currentIndex: number, array: ReadonlyArray<ConfigPatch<T>>) => ConfigPatch<T>): ConfigPatch<T>; (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigP…;
find: { (predicate: (value: ConfigPatch<T>, index: number, obj: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: ConfigPatch<T>, index: number, obj: ReadonlyArray<ConfigPatch<T>>) => unknown, thisA…;
findIndex: (predicate: (value: ConfigPatch<T>, index: number, obj: ReadonlyArray<ConfigPatch<T>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, ConfigPatch<T>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<ConfigPatch<T>>;
includes: (searchElement: ConfigPatch<T>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: ConfigPatch<T>, index: number, array: Array<ConfigPatch<T>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => ConfigPatch<T> | undefined;
findLast: { (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, t…;
findLastIndex: (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<ConfigPatch<T>>;
toSorted: (compareFn?: ((a: ConfigPatch<T>, b: ConfigPatch<T>) => number) | undefined) => Array<ConfigPatch<T>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<ConfigPatch<T>>): Array<ConfigPatch<T>>; (start: number, deleteCount?: number): Array<ConfigPatch<T>> };
with: (index: number, value: ConfigPatch<T>) => Array<ConfigPatch<T>>;
};
of: (this: void, self: ReadonlyArray<ConfigPatch<T>>) => ReadonlyArray<ConfigPatch<T>>;
context: (self: ReadonlyArray<ConfigPatch<T>>) => Context.Context<never>;
use: (f: (service: ReadonlyArray<ConfigPatch<T>>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: ReadonlyArray<ConfigPatch<T>>) => A) => Effect.Effect<A, never, never>;
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;
}
tag = const resourceConfigureTag: <T>(
resourceId: string
) => Context.ServiceClass<
never,
string,
readonly ConfigPatch<T>[]
>
resourceConfigureTag<function (type parameter) T in <T extends object>(resourceId: string, patch: ConfigPatch<T>): Layer.Layer<never>T>(resourceId: stringresourceId);
return import LayerLayer.const effect: <never, readonly ConfigPatch<T>[], never, never>(service: Context.Key<never, readonly ConfigPatch<T>[]>, effect: Effect.Effect<readonly ConfigPatch<T>[], never, never>) => Layer.Layer<never, never, never> (+1 overload)Constructs a layer from an effect that produces a single service.
When to use
Use when you need to construct a Layer-provided service with an Effect,
dependencies, or scoped resource acquisition.
Details
This allows you to create a Layer from an Effect that produces a service.
The Effect is executed in the scope of the layer, allowing for proper
resource management.
Example (Creating a layer from an effect)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layer = Layer.effect(Database,
Effect.sync(() => ({
query: (sql: string) => Effect.succeed(`Query: ${sql}`)
}))
)
effect(
const tag: Context.ServiceClass<
never,
string,
ReadonlyArray<ConfigPatch<T>>
>
const tag: {
key: Identifier;
Service: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<ConfigPatch<T>>>): Array<ConfigPatch<T>>; (...items: Array<ConfigPatch<T> | ConcatArray<ConfigPatch<T>>>): Array<ConfigPatch<T>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<ConfigPatch<T>>;
indexOf: (searchElement: ConfigPatch<T>, fromIndex?: number) => number;
lastIndexOf: (searchElement: ConfigPatch<T>, fromIndex?: number) => number;
every: { (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unk…;
some: (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, thisAr…;
reduce: { (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigPatch<T>, currentIndex: number, array: ReadonlyArray<ConfigPatch<T>>) => ConfigPatch<T>): ConfigPatch<T>; (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigP…;
reduceRight: { (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigPatch<T>, currentIndex: number, array: ReadonlyArray<ConfigPatch<T>>) => ConfigPatch<T>): ConfigPatch<T>; (callbackfn: (previousValue: ConfigPatch<T>, currentValue: ConfigP…;
find: { (predicate: (value: ConfigPatch<T>, index: number, obj: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: ConfigPatch<T>, index: number, obj: ReadonlyArray<ConfigPatch<T>>) => unknown, thisA…;
findIndex: (predicate: (value: ConfigPatch<T>, index: number, obj: ReadonlyArray<ConfigPatch<T>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, ConfigPatch<T>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<ConfigPatch<T>>;
includes: (searchElement: ConfigPatch<T>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: ConfigPatch<T>, index: number, array: Array<ConfigPatch<T>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => ConfigPatch<T> | undefined;
findLast: { (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, t…;
findLastIndex: (predicate: (value: ConfigPatch<T>, index: number, array: ReadonlyArray<ConfigPatch<T>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<ConfigPatch<T>>;
toSorted: (compareFn?: ((a: ConfigPatch<T>, b: ConfigPatch<T>) => number) | undefined) => Array<ConfigPatch<T>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<ConfigPatch<T>>): Array<ConfigPatch<T>>; (start: number, deleteCount?: number): Array<ConfigPatch<T>> };
with: (index: number, value: ConfigPatch<T>) => Array<ConfigPatch<T>>;
};
of: (this: void, self: ReadonlyArray<ConfigPatch<T>>) => ReadonlyArray<ConfigPatch<T>>;
context: (self: ReadonlyArray<ConfigPatch<T>>) => Context.Context<never>;
use: (f: (service: ReadonlyArray<ConfigPatch<T>>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: ReadonlyArray<ConfigPatch<T>>) => A) => Effect.Effect<A, never, never>;
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;
}
tag,
const resourcePatches: <T extends object>(
resourceId: string
) => Effect.Effect<ReadonlyArray<ConfigPatch<T>>>
All configure patches in context for resourceId, in merge order.
resourcePatches<function (type parameter) T in <T extends object>(resourceId: string, patch: ConfigPatch<T>): Layer.Layer<never>T>(resourceId: stringresourceId).Pipeable.pipe<Effect.Effect<readonly ConfigPatch<T>[], never, never>, Effect.Effect<ConfigPatch<T>[], never, never>>(this: Effect.Effect<readonly ConfigPatch<T>[], never, never>, ab: (_: Effect.Effect<readonly ConfigPatch<T>[], never, never>) => Effect.Effect<ConfigPatch<T>[], never, never>): Effect.Effect<ConfigPatch<T>[], never, never> (+21 overloads)pipe(
import EffectEffect.const map: <readonly ConfigPatch<T>[], ConfigPatch<T>[]>(f: (a: readonly ConfigPatch<T>[]) => ConfigPatch<T>[]) => <E, R>(self: Effect.Effect<readonly ConfigPatch<T>[], E, R>) => Effect.Effect<ConfigPatch<T>[], E, R> (+1 overload)Transforms the value inside an effect by applying a function to it.
When to use
Use to transform an effect's success value with a function that returns a
plain value, producing a new effect without changing the original effect's
typed error or context requirements.
Details
map takes a function and applies it to the value contained within an
effect, creating a new effect with the transformed value.
It's important to note that effects are immutable, meaning that the original
effect is not modified. Instead, a new effect is returned with the updated
value.
Example (Choosing map syntax variants)
import { Effect, pipe } from "effect"
const myEffect = Effect.succeed(1)
const transformation = (n: number) => n + 1
const mappedWithPipe = pipe(myEffect, Effect.map(transformation))
const mappedWithDataFirst = Effect.map(myEffect, transformation)
const mappedWithMethod = myEffect.pipe(Effect.map(transformation))
Example (Adding a service charge)
import { Effect, pipe } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const finalAmount = pipe(
fetchTransactionAmount,
Effect.map(addServiceCharge)
)
Effect.runPromise(finalAmount).then(console.log)
// Output: 101
map((existing: ReadonlyArray<ConfigPatch<T>>existing) => [...existing: ReadonlyArray<ConfigPatch<T>>existing, patch: ConfigPatch<T>patch]),
),
);
};