Package: effect
Module: Effect
Returns the complete context.
When to use
Use to read the complete Context available to the current effect.
Details
This function allows you to access all services that are currently available in the effect’s environment. This can be useful for debugging, introspection, or when you need to pass the entire context to another function.
Example (Reading the full context)
import { Console, Context, Effect, Option } from "effect"
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
const program = Effect.gen(function*() {
const allServices = yield* Effect.context()
// Check if specific services are available
const loggerOption = Context.getOption(allServices, Logger)
const databaseOption = Context.getOption(allServices, Database)
yield* Console.log(`Logger available: ${Option.isSome(loggerOption)}`)
yield* Console.log(`Database available: ${Option.isSome(databaseOption)}`)
})
const context = Context.make(Logger, { log: console.log })
.pipe(Context.add(Database, { query: () => "result" }))
const provided = Effect.provideContext(program, context)
See
contextWith for deriving an effect from the complete contextservice for reading one service from the contextSignature
declare const context: <R = never>() => Effect<Context.Context<R>, never, R>
Since v2.0.0