CurrentMemoMapContext service for the current MemoMap used in layer construction.
When to use
Use when building custom layer operations that need to access the current memoization map from the fiber context.
Details
This service wraps a MemoMap as a Context.Service, making it available
for dependency injection during layer construction.
export class class CurrentMemoMapclass CurrentMemoMap {
key: Identifier;
Service: {
get: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn> | undefined;
getOrElseMemoize: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope, build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn>) => Effect<Context.Context<ROut>, E, RIn>;
};
}
Context service for the current MemoMap used in layer construction.
When to use
Use when building custom layer operations that need to access the current
memoization map from the fiber context.
Details
This service wraps a MemoMap as a Context.Service, making it available
for dependency injection during layer construction.
CurrentMemoMap extends import ContextContext.Service<class CurrentMemoMapclass CurrentMemoMap {
key: Identifier;
Service: {
get: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn> | undefined;
getOrElseMemoize: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope, build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn>) => Effect<Context.Context<ROut>, E, RIn>;
};
}
Context service for the current MemoMap used in layer construction.
When to use
Use when building custom layer operations that need to access the current
memoization map from the fiber context.
Details
This service wraps a MemoMap as a Context.Service, making it available
for dependency injection during layer construction.
CurrentMemoMap, MemoMap>()("effect/Layer/CurrentMemoMap") {
static CurrentMemoMap.forkOrCreate<Services>(self: Context.Context<Services>): MemoMapforkOrCreate<function (type parameter) Services in CurrentMemoMap.forkOrCreate<Services>(self: Context.Context<Services>): MemoMapServices>(self: Context.Context<Services>(parameter) self: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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.type Context.Context = /*unresolved*/ anyContext<function (type parameter) Services in CurrentMemoMap.forkOrCreate<Services>(self: Context.Context<Services>): MemoMapServices>): MemoMap {
const const current: anycurrent = import ContextContext.getOrUndefined(self: Context.Context<Services>(parameter) self: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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, class CurrentMemoMapclass CurrentMemoMap {
key: Identifier;
Service: {
get: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn> | undefined;
getOrElseMemoize: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope, build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn>) => Effect<Context.Context<ROut>, E, RIn>;
};
forkOrCreate: <Services>(self: Context.Context<Services>) => MemoMap;
of: (this: void, self: MemoMap) => MemoMap;
context: (self: MemoMap) => Context.Context<CurrentMemoMap>;
use: (f: (service: MemoMap) => Effect<A, E, R>) => Effect<A, E, CurrentMemoMap | R>;
useSync: (f: (service: MemoMap) => A) => Effect<A, never, CurrentMemoMap>;
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;
}
Context service for the current MemoMap used in layer construction.
When to use
Use when building custom layer operations that need to access the current
memoization map from the fiber context.
Details
This service wraps a MemoMap as a Context.Service, making it available
for dependency injection during layer construction.
CurrentMemoMap)
return const current: anycurrent ? const forkMemoMapUnsafe: (
parent: MemoMap
) => MemoMap
Constructs a child MemoMap synchronously, allowing it to reuse layers
already memoized in the parent while isolating any new layer allocations to
the child map.
When to use
Use to synchronously fork a memo map for manual layer building when child
builds should see parent memoized layers without writing newly built layers
back to the parent.
forkMemoMapUnsafe(const current: MemoMapconst current: {
get: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn> | undefined;
getOrElseMemoize: <RIn, E, ROut>(layer: Layer<ROut, E, RIn>, scope: Scope.Scope, build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<ROut>, E, RIn>) => Effect<Context.Context<ROut>, E, RIn>;
}
current) : const makeMemoMapUnsafe: () => MemoMapConstructs a MemoMap synchronously so it can be used to build additional layers.
Example (Creating a memo map unsafely)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
// Create a memo map for manual layer building
const program = Effect.gen(function*() {
const memoMap = Layer.makeMemoMapUnsafe()
const scope = yield* Effect.scope
const dbLayer = Layer.succeed(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result"))
})
const context = yield* Layer.buildWithMemoMap(dbLayer, memoMap, scope)
return Context.get(context, Database)
})
makeMemoMapUnsafe()
}
}