<Services = never>(mapUnsafe: ReadonlyMap<string, any>): Context<Services>Creates a Context from an existing service map.
When to use
Use when constructing a low-level Context from a trusted map whose lifecycle
you control.
Gotchas
This is unsafe because later mutation of the provided map can affect the
created Context. Prefer empty, make, add, or merge for normal
Context construction.
Example (Creating a context from a map)
import { Context } from "effect"
// Create a context from a Map (unsafe)
const map = new Map([
["Logger", { log: (msg: string) => console.log(msg) }]
])
const context = Context.makeUnsafe(map)export const const makeUnsafe: <Services = never>(
mapUnsafe: ReadonlyMap<string, any>
) => Context<Services>
Creates a Context from an existing service map.
When to use
Use when constructing a low-level Context from a trusted map whose lifecycle
you control.
Gotchas
This is unsafe because later mutation of the provided map can affect the
created Context. Prefer empty, make, add, or merge for normal
Context construction.
Example (Creating a context from a map)
import { Context } from "effect"
// Create a context from a Map (unsafe)
const map = new Map([
["Logger", { log: (msg: string) => console.log(msg) }]
])
const context = Context.makeUnsafe(map)
makeUnsafe = <function (type parameter) Services in <Services = never>(mapUnsafe: ReadonlyMap<string, any>): Context<Services>Services = never>(mapUnsafe: ReadonlyMap<string, any>mapUnsafe: interface ReadonlyMap<K, V>ReadonlyMap<string, any>): 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 <Services = never>(mapUnsafe: ReadonlyMap<string, any>): Context<Services>Services> => {
const const self: anyself = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const Proto: Omit<
Context<never>,
"mapUnsafe" | "mutable"
>
Proto)
const self: anyself.mapUnsafe = mapUnsafe: ReadonlyMap<string, any>mapUnsafe
const self: anyself.mutable = false
return const self: anyself
}