<A, R, E>(acquire: Effect.Effect<A, E, R>): (
self: ScopedRef<A>
) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>
<A, R, E>(
self: ScopedRef<A>,
acquire: Effect.Effect<A, E, R>
): Effect.Effect<void, E, Exclude<R, Scope.Scope>>Sets the value of this reference to a newly acquired scoped value, releasing any resources associated with the old value.
When to use
Use to replace the current value of an existing ScopedRef with a newly
acquired scoped value while releasing resources for the previous value.
Details
This method will not return until either the reference is successfully changed to the new value, with old resources released, or until the attempt to acquire a new value fails.
export const const set: {
<A, R, E>(acquire: Effect.Effect<A, E, R>): (
self: ScopedRef<A>
) => Effect.Effect<
void,
E,
Exclude<R, Scope.Scope>
>
<A, R, E>(
self: ScopedRef<A>,
acquire: Effect.Effect<A, E, R>
): Effect.Effect<
void,
E,
Exclude<R, Scope.Scope>
>
}
Sets the value of this reference to a newly acquired scoped value, releasing
any resources associated with the old value.
When to use
Use to replace the current value of an existing ScopedRef with a newly
acquired scoped value while releasing resources for the previous value.
Details
This method will not return until either the reference is successfully
changed to the new value, with old resources released, or until the attempt
to acquire a new value fails.
set: {
<function (type parameter) A in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>A, function (type parameter) R in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>R, function (type parameter) E in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>E>(acquire: Effect.Effect<A, E, R>(parameter) acquire: {
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;
}
acquire: import EffectEffect.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, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>A, function (type parameter) E in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>E, function (type parameter) R in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>R>): (self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self: interface ScopedRef<in out A>A ScopedRef is a reference whose value is associated with resources,
which must be released properly. You can both get the current value of any
ScopedRef, as well as set it to a new value (which may require new
resources). The reference itself takes care of properly releasing resources
for the old value whenever a new value is obtained.
When to use
Use when an application needs to keep a current resource-backed value and
later replace it with another acquired value while ensuring the previous
value is released.
ScopedRef<function (type parameter) A in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>A>) => import EffectEffect.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<void, function (type parameter) E in <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.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, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>R, import ScopeScope.Scope>>
<function (type parameter) A in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>A, function (type parameter) R in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>R, function (type parameter) E in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>E>(self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self: interface ScopedRef<in out A>A ScopedRef is a reference whose value is associated with resources,
which must be released properly. You can both get the current value of any
ScopedRef, as well as set it to a new value (which may require new
resources). The reference itself takes care of properly releasing resources
for the old value whenever a new value is obtained.
When to use
Use when an application needs to keep a current resource-backed value and
later replace it with another acquired value while ensuring the previous
value is released.
ScopedRef<function (type parameter) A in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>A>, acquire: Effect.Effect<A, E, R>(parameter) acquire: {
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;
}
acquire: import EffectEffect.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, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>A, function (type parameter) E in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>E, function (type parameter) R in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>R>): import EffectEffect.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<void, function (type parameter) E in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.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, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>R, import ScopeScope.Scope>>
} = dual<(...args: Array<any>) => any, <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>>(arity: 2, body: <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>): ((...args: Array<any>) => any) & (<A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
2,
import EffectEffect.const fnUntraced: <Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, [self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>], Effect.Effect<void, E, Exclude<R, Scope.Scope>>, Effect.Effect<void, E, Exclude<R, Scope.Scope>>>(body: (this: unassigned, self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>) => Generator<Effect.Effect<void, never, never> | Effect.Effect<...>, void, never>, a: (_: Effect.Effect<...>, self: ScopedRef<...>, acquire: Effect.Effect<...>) => Effect.Effect<...>, b: (_: Effect.Effect<...>, self: ScopedRef<...>, acquire: Effect.Effect<...>) => Effect.Effect<...>) => <A, R, E>(self: ScopedRef<...>, acquire: Effect.Effect<...>) => Effect.Effect<...> (+41 overloads)fnUntraced(
function*<function (type parameter) A in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>A, function (type parameter) R in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>R, function (type parameter) E in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>E>(
self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self: interface ScopedRef<in out A>A ScopedRef is a reference whose value is associated with resources,
which must be released properly. You can both get the current value of any
ScopedRef, as well as set it to a new value (which may require new
resources). The reference itself takes care of properly releasing resources
for the old value whenever a new value is obtained.
When to use
Use when an application needs to keep a current resource-backed value and
later replace it with another acquired value while ensuring the previous
value is released.
ScopedRef<function (type parameter) A in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>A>,
acquire: Effect.Effect<A, E, R>(parameter) acquire: {
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;
}
acquire: import EffectEffect.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, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>A, function (type parameter) E in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>E, function (type parameter) R in <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Generator<Effect.Effect<void, never, never> | Effect.Effect<A, E, Exclude<R, Scope.Scope>>, void, any>R>
) {
yield* import ScopeScope.const close: <A, E>(
self: Scope,
exit: Exit<A, E>
) => Effect<void>
Closes a scope and runs its registered finalizers.
When to use
Use to close a scope manually with a specific exit value.
Details
Finalizers run in the scope's configured order and receive the supplied
Exit.
Example (Running scope finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const resourceManagement = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Add multiple finalizers
yield* Scope.addFinalizer(scope, Console.log("Close database connection"))
yield* Scope.addFinalizer(scope, Console.log("Close file handle"))
yield* Scope.addFinalizer(scope, Console.log("Release memory"))
// Do some work...
yield* Console.log("Performing operations...")
// Close scope - finalizers run in reverse order of registration
yield* Scope.close(scope, Exit.succeed("Success!"))
// Output: "Release memory", "Close file handle", "Close database connection"
})
close(self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self.ScopedRef<A>.backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>(property) ScopedRef<A>.backing: {
backing: Ref.Ref<A>;
semaphore: Semaphore.Semaphore;
ref: MutableRef.MutableRef<A>;
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; <…;
}
backing.SynchronizedRef<readonly [Closeable, A]>.backing: Ref.Ref<A>(property) SynchronizedRef<readonly [Closeable, A]>.backing: {
ref: MutableRef.MutableRef<A>;
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; <…;
}
backing.Ref<readonly [Closeable, A]>.ref: MutableRef.MutableRef<A>(property) Ref<readonly [Closeable, A]>.ref: {
current: T;
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;
}
ref.MutableRef<readonly [Closeable, A]>.current: readonly [Scope.Closeable, A](property) MutableRef<readonly [Closeable, A]>.current: {
0: Scope.Closeable;
1: A;
length: 2;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Scope.Closeable | A>>): Array<Scope.Closeable | A>; (...items: Array<Scope.Closeable | A | ConcatArray<Scope.Closeable | A>>): Array<Scope.Closeable | A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Scope.Closeable | A>;
indexOf: (searchElement: Scope.Closeable | A, fromIndex?: number) => number;
lastIndexOf: (searchElement: Scope.Closeable | A, fromIndex?: number) => number;
every: { (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Cl…;
some: (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>…;
reduce: { (callbackfn: (previousValue: Scope.Closeable | A, currentValue: Scope.Closeable | A, currentIndex: number, array: ReadonlyArray<Scope.Closeable | A>) => Scope.Closeable | A): Scope.Closeable | A; (callbackfn: (previousValue: Scope.Closea…;
reduceRight: { (callbackfn: (previousValue: Scope.Closeable | A, currentValue: Scope.Closeable | A, currentIndex: number, array: ReadonlyArray<Scope.Closeable | A>) => Scope.Closeable | A): Scope.Closeable | A; (callbackfn: (previousValue: Scope.Closea…;
find: { (predicate: (value: Scope.Closeable | A, index: number, obj: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Scope.Closeable | A, index: number, obj: ReadonlyArray<Scope.Closeable | A…;
findIndex: (predicate: (value: Scope.Closeable | A, index: number, obj: ReadonlyArray<Scope.Closeable | A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Scope.Closeable | A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Scope.Closeable | A>;
includes: (searchElement: Scope.Closeable | A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Scope.Closeable | A, index: number, array: Array<Scope.Closeable | A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Scope.Closeable | A | undefined;
findLast: { (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable…;
findLastIndex: (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Scope.Closeable | A>;
toSorted: (compareFn?: ((a: Scope.Closeable | A, b: Scope.Closeable | A) => number) | undefined) => Array<Scope.Closeable | A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Scope.Closeable | A>): Array<Scope.Closeable | A>; (start: number, deleteCount?: number): Array<Scope.Closeable | A> };
with: (index: number, value: Scope.Closeable | A) => Array<Scope.Closeable | A>;
}
current[0], import ExitExit.const void: Exit.Exit<void, never>Provides a pre-allocated successful Exit with a void value.
When to use
Use when you need a shared successful Exit with no meaningful value.
Details
Equivalent to Exit.succeed(undefined) but shared as a single instance,
avoiding allocation for a common case.
Example (Referencing the void Exit)
import { Exit } from "effect"
const exit = Exit.void
console.log(Exit.isSuccess(exit)) // true
void)
const const scope: Scope.Closeableconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope = import ScopeScope.const makeUnsafe: (
finalizerStrategy?: "sequential" | "parallel"
) => Closeable
Creates a new Scope synchronously without wrapping it in an Effect.
This is useful when you need a scope immediately but should be used with caution
as it doesn't provide the same safety guarantees as the Effect-wrapped version.
When to use
Use when a scope must be allocated synchronously and the caller will close it
manually.
Example (Creating a scope synchronously)
import { Console, Effect, Exit, Scope } from "effect"
// Create a scope immediately
const scope = Scope.makeUnsafe("sequential")
// Use it in an Effect program
const program = Effect.gen(function*() {
yield* Scope.addFinalizer(scope, Console.log("Cleanup"))
yield* Scope.close(scope, Exit.void)
})
makeUnsafe()
const const value: Avalue = yield* acquire: Effect.Effect<A, E, R>(parameter) acquire: {
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;
}
acquire.Pipeable.pipe<Effect.Effect<A, E, R>, Effect.Effect<A, E, Exclude<R, Scope.Scope>>, Effect.Effect<A, E, Exclude<R, Scope.Scope>>>(this: Effect.Effect<A, E, R>, ab: (_: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Scope.Scope>>, bc: (_: Effect.Effect<A, E, Exclude<R, Scope.Scope>>) => Effect.Effect<A, E, Exclude<R, Scope.Scope>>): Effect.Effect<...> (+21 overloads)pipe(
import ScopeScope.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>>
}
provide(const scope: Scope.Closeableconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope),
import EffectEffect.const tapCause: {
<E, X, E2, R2>(
f: (
cause: Cause.Cause<NoInfer<E>>
) => Effect<X, E2, R2>
): <A, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R2 | R>
<A, E, R, X, E2, R2>(
self: Effect<A, E, R>,
f: (
cause: Cause.Cause<E>
) => Effect<X, E2, R2>
): Effect<A, E | E2, R | R2>
}
tapCause((cause: Cause<NoInfer<E>>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause) => import ScopeScope.const close: <A, E>(
self: Scope,
exit: Exit<A, E>
) => Effect<void>
Closes a scope and runs its registered finalizers.
When to use
Use to close a scope manually with a specific exit value.
Details
Finalizers run in the scope's configured order and receive the supplied
Exit.
Example (Running scope finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const resourceManagement = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Add multiple finalizers
yield* Scope.addFinalizer(scope, Console.log("Close database connection"))
yield* Scope.addFinalizer(scope, Console.log("Close file handle"))
yield* Scope.addFinalizer(scope, Console.log("Release memory"))
// Do some work...
yield* Console.log("Performing operations...")
// Close scope - finalizers run in reverse order of registration
yield* Scope.close(scope, Exit.succeed("Success!"))
// Output: "Release memory", "Close file handle", "Close database connection"
})
close(const scope: Scope.Closeableconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, import ExitExit.const failCause: <E>(
cause: Cause.Cause<E>
) => Exit<never, E>
Creates a failed Exit from a Cause.
When to use
Use when you already have a Cause<E> and want to wrap it in an Exit
for advanced error handling where you need full control over the Cause
structure.
Details
Returns a Failure<never, E>. If you only have an error value, use
fail
instead.
Example (Creating a failed Exit from a Cause)
import { Cause, Exit } from "effect"
const cause = Cause.fail("Something went wrong")
const exit = Exit.failCause(cause)
console.log(Exit.isFailure(exit)) // true
failCause(cause: Cause<NoInfer<E>>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause)))
)
self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self.ScopedRef<A>.backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>(property) ScopedRef<A>.backing: {
backing: Ref.Ref<A>;
semaphore: Semaphore.Semaphore;
ref: MutableRef.MutableRef<A>;
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; <…;
}
backing.SynchronizedRef<readonly [Closeable, A]>.backing: Ref.Ref<A>(property) SynchronizedRef<readonly [Closeable, A]>.backing: {
ref: MutableRef.MutableRef<A>;
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; <…;
}
backing.Ref<readonly [Closeable, A]>.ref: MutableRef.MutableRef<A>(property) Ref<readonly [Closeable, A]>.ref: {
current: T;
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;
}
ref.MutableRef<readonly [Closeable, A]>.current: readonly [Scope.Closeable, A](property) MutableRef<readonly [Closeable, A]>.current: {
0: Scope.Closeable;
1: A;
length: 2;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Scope.Closeable | A>>): Array<Scope.Closeable | A>; (...items: Array<Scope.Closeable | A | ConcatArray<Scope.Closeable | A>>): Array<Scope.Closeable | A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Scope.Closeable | A>;
indexOf: (searchElement: Scope.Closeable | A, fromIndex?: number) => number;
lastIndexOf: (searchElement: Scope.Closeable | A, fromIndex?: number) => number;
every: { (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Cl…;
some: (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>…;
reduce: { (callbackfn: (previousValue: Scope.Closeable | A, currentValue: Scope.Closeable | A, currentIndex: number, array: ReadonlyArray<Scope.Closeable | A>) => Scope.Closeable | A): Scope.Closeable | A; (callbackfn: (previousValue: Scope.Closea…;
reduceRight: { (callbackfn: (previousValue: Scope.Closeable | A, currentValue: Scope.Closeable | A, currentIndex: number, array: ReadonlyArray<Scope.Closeable | A>) => Scope.Closeable | A): Scope.Closeable | A; (callbackfn: (previousValue: Scope.Closea…;
find: { (predicate: (value: Scope.Closeable | A, index: number, obj: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Scope.Closeable | A, index: number, obj: ReadonlyArray<Scope.Closeable | A…;
findIndex: (predicate: (value: Scope.Closeable | A, index: number, obj: ReadonlyArray<Scope.Closeable | A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Scope.Closeable | A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Scope.Closeable | A>;
includes: (searchElement: Scope.Closeable | A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Scope.Closeable | A, index: number, array: Array<Scope.Closeable | A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Scope.Closeable | A | undefined;
findLast: { (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable…;
findLastIndex: (predicate: (value: Scope.Closeable | A, index: number, array: ReadonlyArray<Scope.Closeable | A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Scope.Closeable | A>;
toSorted: (compareFn?: ((a: Scope.Closeable | A, b: Scope.Closeable | A) => number) | undefined) => Array<Scope.Closeable | A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Scope.Closeable | A>): Array<Scope.Closeable | A>; (start: number, deleteCount?: number): Array<Scope.Closeable | A> };
with: (index: number, value: Scope.Closeable | A) => Array<Scope.Closeable | A>;
}
current = [const scope: Scope.Closeableconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, const value: Avalue]
},
import EffectEffect.const uninterruptible: <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, R>
Returns a new effect that disables interruption for the given effect.
Example (Preventing interruption)
import { Console, Effect, Fiber } from "effect"
const criticalTask = Effect.gen(function*() {
yield* Console.log("Starting critical section...")
yield* Effect.sleep("2 seconds")
yield* Console.log("Critical section completed")
})
const program = Effect.uninterruptible(criticalTask)
const fiber = Effect.runFork(program)
// Even if interrupted, the critical task will complete
Effect.runPromise(Fiber.interrupt(fiber))
uninterruptible,
(effect: Effect.Effect<
void,
E,
Exclude<R, Scope.Scope>
>
(parameter) effect: {
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;
}
effect, self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self) => self: ScopedRef<A>(parameter) self: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
self.ScopedRef<A>.backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>(property) ScopedRef<A>.backing: {
backing: Ref.Ref<A>;
semaphore: Semaphore.Semaphore;
ref: MutableRef.MutableRef<A>;
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; <…;
}
backing.SynchronizedRef<readonly [Closeable, A]>.semaphore: Semaphore.Semaphore(property) SynchronizedRef<readonly [Closeable, A]>.semaphore: {
resize: (this: Semaphore, permits: number) => Effect.Effect<void>;
withPermits: (this: Semaphore, permits: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermit: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermitsIfAvailable: (this: Semaphore, permits: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>;
take: (this: Semaphore, permits: number) => Effect.Effect<number>;
release: (this: Semaphore, permits: number) => Effect.Effect<number>;
releaseAll: Effect.Effect<number>;
}
semaphore.Semaphore.withPermit<A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>Runs an effect with the given number of permits and releases the permits
when the effect completes.
When to use
Use to run an effect while holding exactly one semaphore permit.
Details
This function acquires the specified number of permits before executing
the provided effect. Once the effect finishes, the permits are released.
If insufficient permits are available, the function will wait until they
are released by other tasks.
withPermit(effect: Effect.Effect<
void,
E,
Exclude<R, Scope.Scope>
>
(parameter) effect: {
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;
}
effect)
)
)