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.const Service: {
<Identifier, Shape = Identifier>(
key: string
): Service<Identifier, Shape>
<Self, Shape>(): <
Identifier extends string,
E,
R = Types.unassigned,
Args extends ReadonlyArray<any> = never
>(
id: Identifier,
options?:
| {
readonly make:
| ((
...args: Args
) => Effect<Shape, E, R>)
| Effect<Shape, E, R>
| undefined
}
| undefined
) => ServiceClass<Self, Identifier, Shape> &
([Types.unassigned] extends [R]
? unknown
: {
readonly make: [Args] extends [never]
? Effect<Shape, E, R>
: (
...args: Args
) => Effect<Shape, E, R>
})
<Self>(): <
Identifier extends string,
Make extends
| Effect<any, any, any>
| ((...args: any) => Effect<any, any, any>)
>(
id: Identifier,
options: { readonly make: Make }
) => ServiceClass<
Self,
Identifier,
Make extends
| Effect<infer _A, infer _E, infer _R>
| ((
...args: infer _Args
) => Effect<infer _A, infer _E, infer _R>)
? _A
: never
> & { readonly make: Make }
}
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.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) Services in CurrentMemoMap.forkOrCreate<Services>(self: Context.Context<Services>): MemoMapServices>): MemoMap {
const const current: MemoMap | undefinedcurrent = import ContextContext.const getOrUndefined: {
<S, I>(key: Key<I, S>): <Services>(
self: Context<Services>
) => S | undefined
<Services, S, I>(
self: Context<Services>,
key: Key<I, S>
): S | undefined
}
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: MemoMap | undefinedcurrent ? 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()
}
}