(value: Scope): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, Scope>>
<A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<
A,
E,
Exclude<R, Scope>
>Provides a concrete Scope to an effect.
When to use
Use to run an effect that requires Scope with a scope managed by the
caller.
Details
Providing the scope removes the Scope requirement from the effect context.
Example (Providing a scope)
import { Console, Effect, Scope } from "effect"
// An effect that requires a Scope
const program = Effect.gen(function*() {
const scope = yield* Scope.Scope
yield* Scope.addFinalizer(scope, Console.log("Cleanup"))
yield* Console.log("Working...")
})
// Provide a scope to the program
const withScope = Effect.gen(function*() {
const scope = yield* Scope.make()
yield* Scope.provide(scope)(program)
})combinators
Source effect/Scope.ts:3174 lines
export const const provide: {
(value: Scope): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, Scope>>
<A, E, R>(
self: Effect<A, E, R>,
value: Scope
): Effect<A, E, Exclude<R, Scope>>
}
Provides a concrete Scope to an effect.
When to use
Use to run an effect that requires Scope with a scope managed by the
caller.
Details
Providing the scope removes the Scope requirement from the effect context.
Example (Providing a scope)
import { Console, Effect, Scope } from "effect"
// An effect that requires a Scope
const program = Effect.gen(function*() {
const scope = yield* Scope.Scope
yield* Scope.addFinalizer(scope, Console.log("Cleanup"))
yield* Console.log("Working...")
})
// Provide a scope to the program
const withScope = Effect.gen(function*() {
const scope = yield* Scope.make()
yield* Scope.provide(scope)(program)
})
provide: {
(value: Scope(parameter) value: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
value: Scope): <function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>R>(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: import EffectEffect<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>R>) => import EffectEffect<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>E, type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<A, E, Exclude<R, Scope>>R, Scope>>
<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>R>(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: import EffectEffect<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>R>, value: Scope(parameter) value: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
value: Scope): import EffectEffect<function (type parameter) A in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>E, type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>R, Scope>>
} = import effecteffect.const provideScope: {
(value: Scope.Scope): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<
A,
E,
Exclude<R, Scope.Scope>
>
<A, E, R>(
self: Effect.Effect<A, E, R>,
value: Scope.Scope
): Effect.Effect<A, E, Exclude<R, Scope.Scope>>
}
provideScopeReferenced by 12 symbols