<R2, R>(
f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>
): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>
<A, E, R, R2>(
self: Effect<A, E, R>,
f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>
): Effect<A, E, R2>Provides part of the required context while leaving the rest unchanged.
Details
This function allows you to transform the context required by an effect, providing part of the context and leaving the rest to be fulfilled later.
Example (Updating the context before running)
import { Context, Effect } from "effect"
// Define services
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
const Config = Context.Service<{
name: string
}>("Config")
const program = Effect.service(Config).pipe(
Effect.map((config) => `Hello ${config.name}!`)
)
// Transform services by providing Config while keeping Logger requirement
const configured = program.pipe(
Effect.updateContext((context: Context.Context<typeof Logger>) =>
Context.add(context, Config, { name: "World" })
)
)
// The effect now requires only Logger service
const result = Effect.provideService(configured, Logger, {
log: (msg) => console.log(msg)
})export const const updateContext: {
<R2, R>(
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): <A, E>(
self: Effect<A, E, R>
) => Effect<A, E, R2>
<A, E, R, R2>(
self: Effect<A, E, R>,
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): Effect<A, E, R2>
}
Provides part of the required context while leaving the rest unchanged.
Details
This function allows you to transform the context required by an effect,
providing part of the context and leaving the rest to be fulfilled later.
Example (Updating the context before running)
import { Context, Effect } from "effect"
// Define services
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
const Config = Context.Service<{
name: string
}>("Config")
const program = Effect.service(Config).pipe(
Effect.map((config) => `Hello ${config.name}!`)
)
// Transform services by providing Config while keeping Logger requirement
const configured = program.pipe(
Effect.updateContext((context: Context.Context<typeof Logger>) =>
Context.add(context, Config, { name: "World" })
)
)
// The effect now requires only Logger service
const result = Effect.provideService(configured, Logger, {
log: (msg) => console.log(msg)
})
updateContext: {
<function (type parameter) R2 in <R2, R>(f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>R2, function (type parameter) R in <R2, R>(f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>R>(
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
f: (context: Context.Context<R2>(parameter) context: {
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;
}
context: import ContextContext.type Context.Context = /*unresolved*/ anyContext<function (type parameter) R2 in <R2, R>(f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>R2>) => import ContextContext.type Context.Context = /*unresolved*/ anyContext<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) R in <R2, R>(f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>R>>
): <function (type parameter) A in <A, E>(self: Effect<A, E, R>): Effect<A, E, R2>A, function (type parameter) E in <A, E>(self: Effect<A, E, R>): Effect<A, E, R2>E>(self: Effect<A, E, R>(parameter) self: {
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: 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<function (type parameter) A in <A, E>(self: Effect<A, E, R>): Effect<A, E, R2>A, function (type parameter) E in <A, E>(self: Effect<A, E, R>): Effect<A, E, R2>E, function (type parameter) R in <R2, R>(f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>R>) => 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<function (type parameter) A in <A, E>(self: Effect<A, E, R>): Effect<A, E, R2>A, function (type parameter) E in <A, E>(self: Effect<A, E, R>): Effect<A, E, R2>E, function (type parameter) R2 in <R2, R>(f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): <A, E>(self: Effect<A, E, R>) => Effect<A, E, R2>R2>
<function (type parameter) A in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>A, function (type parameter) E in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>E, function (type parameter) R in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>R, function (type parameter) R2 in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>R2>(
self: Effect<A, E, R>(parameter) self: {
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: 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<function (type parameter) A in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>A, function (type parameter) E in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>E, function (type parameter) R in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>R>,
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
f: (context: Context.Context<R2>(parameter) context: {
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;
}
context: import ContextContext.type Context.Context = /*unresolved*/ anyContext<function (type parameter) R2 in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>R2>) => import ContextContext.type Context.Context = /*unresolved*/ anyContext<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) R in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>R>>
): 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<function (type parameter) A in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>A, function (type parameter) E in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>E, function (type parameter) R2 in <A, E, R, R2>(self: Effect<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Effect<A, E, R2>R2>
} = import internalinternal.const updateContext: {
<R2, R>(
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): <A, E>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R2>
<A, E, R, R2>(
self: Effect.Effect<A, E, R>,
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): Effect.Effect<A, E, R2>
}
updateContext