<R = never>(): Effect<Context.Context<R>, never, R>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)export const const context: <R = never>() => Effect<
Context.Context<R>,
never,
R
>
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)
context: <function (type parameter) R in <R = never>(): Effect<Context.Context<R>, never, R>R = never>() => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<import ContextContext.type Context.Context = /*unresolved*/ anyContext<function (type parameter) R in <R = never>(): Effect<Context.Context<R>, never, R>R>, never, function (type parameter) R in <R = never>(): Effect<Context.Context<R>, never, R>R> = import internalinternal.const context: <
R = never
>() => Effect.Effect<Context.Context<R>>
context