(chunkSize: number, stepSize: number): <A, E, R>(
self: Stream<A, E, R>
) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>
<A, E, R>(
self: Stream<A, E, R>,
chunkSize: number,
stepSize: number
): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>Emits sliding windows of chunkSize elements, advancing by stepSize.
Example (Emitting sliding windows with a step size)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const chunks = yield* Stream.make(1, 2, 3, 4, 5).pipe(
Stream.slidingSize(3, 2),
Stream.runCollect
)
yield* Console.log(chunks)
})
Effect.runPromise(program)
// Output: [ [ 1, 2, 3 ], [ 3, 4, 5 ] ]export const const slidingSize: {
(chunkSize: number, stepSize: number): <
A,
E,
R
>(
self: Stream<A, E, R>
) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>
<A, E, R>(
self: Stream<A, E, R>,
chunkSize: number,
stepSize: number
): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>
}
Emits sliding windows of chunkSize elements, advancing by stepSize.
Example (Emitting sliding windows with a step size)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const chunks = yield* Stream.make(1, 2, 3, 4, 5).pipe(
Stream.slidingSize(3, 2),
Stream.runCollect
)
yield* Console.log(chunks)
})
Effect.runPromise(program)
// Output: [ [ 1, 2, 3 ], [ 3, 4, 5 ] ]
slidingSize: {
(chunkSize: numberchunkSize: number, stepSize: numberstepSize: number): <function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
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 Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>) => interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A>, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>
<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
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 Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>, chunkSize: numberchunkSize: number, stepSize: numberstepSize: number): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A>, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>
} = dual<(...args: Array<any>) => any, <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>>(arity: 3, body: <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>): ((...args: Array<any>) => any) & (<A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>) (+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(
3,
<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
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 Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R>, chunkSize: numberchunkSize: number, stepSize: numberstepSize: number): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A>, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>R> =>
const transformPull: <
A,
E,
R,
B,
E2,
R2,
EX,
RX
>(
self: Stream<A, E, R>,
f: (
pull: Pull.Pull<
Arr.NonEmptyReadonlyArray<A>,
E,
void
>,
scope: Scope.Scope
) => Effect.Effect<
Pull.Pull<
Arr.NonEmptyReadonlyArray<B>,
E2,
void,
R2
>,
EX,
RX
>
) => Stream<
B,
EX | Pull.ExcludeDone<E2>,
R | R2 | RX
>
Derives a stream by transforming its pull effect.
Example (Transforming a pull effect)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3)
const transformed = Stream.transformPull(stream, (pull) => Effect.succeed(pull))
const program = Effect.gen(function*() {
const values = yield* Stream.runCollect(transformed)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
transformPull(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
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, (upstream: Pull.Pull<
readonly [A, ...A[]],
E,
void,
never
>
(parameter) upstream: {
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;
}
upstream, _scope: Scope.Scope(parameter) _scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
_scope) =>
import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => {
let let cause: Cause.Cause<
E | Cause.Done
> | null
cause: import CauseCause.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E | import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done> | null = null
const const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list = import MutableListMutableList.const make: <A>() => MutableList<A>Creates an empty MutableList.
Example (Creating an empty mutable list)
import { MutableList } from "effect"
const list = MutableList.make<string>()
// Add elements
MutableList.append(list, "first")
MutableList.append(list, "second")
MutableList.prepend(list, "beginning")
console.log(list.length) // 3
// Take elements in FIFO order (from head)
console.log(MutableList.take(list)) // "beginning"
console.log(MutableList.take(list)) // "first"
console.log(MutableList.take(list)) // "second"
make<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A>()
let let emitted: booleanemitted = false
const const pull: Pull.Pull<
Arr.NonEmptyReadonlyArray<
Arr.NonEmptyReadonlyArray<A>
>,
E | Cause.Done
>
const pull: {
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;
}
pull: import PullPull.interface Pull<out A, out E = never, out Done = void, out R = never>An effectful pull step that either produces a value, fails with E, or
signals completion with Cause.Done<Done>.
When to use
Use to model one low-level pull step when a consumer repeatedly evaluates an
effect that may emit a value, fail normally, or signal normal completion
through Cause.Done.
Details
Pull represents completion in the error channel so low-level stream
consumers can distinguish ordinary failures from end-of-input and carry a
leftover value when needed.
Pull<
import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A>>,
function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>E | import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done
> = import EffectEffect.const matchCauseEffect: {
<E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
readonly onSuccess: (
a: A
) => Effect<A3, E3, R3>
}): <R>(
self: Effect<A, E, R>
) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
<A, E, R, A2, E2, R2, A3, E3, R3>(
self: Effect<A, E, R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
readonly onSuccess: (
a: A
) => Effect<A3, E3, R3>
}
): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
}
matchCauseEffect(upstream: Pull.Pull<
readonly [A, ...A[]],
E,
void,
never
>
(parameter) upstream: {
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;
}
upstream, {
onSuccess: (
a: readonly [A, ...A[]]
) => Effect.Effect<
readonly [
readonly [A, ...A[]],
...(readonly [A, ...A[]])[]
],
Cause.Done<void> | E,
never
>
onSuccess(arr: readonly [A, ...A[]](parameter) arr: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<A>;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
find: { (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
arr) {
import MutableListMutableList.const appendAllUnsafe: <A>(
self: MutableList<A>,
messages: ReadonlyArray<A>,
mutable?: boolean
) => number
Appends all elements from a ReadonlyArray to the end of the MutableList.
This is an optimized version that can reuse the array when mutable=true.
Returns the number of elements added.
When to use
Use when appending a trusted array directly is worth the optimized path and
you control whether the input may be reused.
Gotchas
When mutable=true, the input array may be modified internally. Only use
mutable=true when you control the array lifecycle.
Example (Appending arrays with optional mutation)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.append(list, 1)
// Safe usage (default mutable=false)
const items = [2, 3, 4]
const added = MutableList.appendAllUnsafe(list, items)
console.log(added) // 3
console.log(items) // [2, 3, 4] - unchanged
// Unsafe but efficient usage (mutable=true)
const mutableItems = [5, 6, 7]
MutableList.appendAllUnsafe(list, mutableItems, true)
// mutableItems may be modified internally for efficiency
console.log(MutableList.takeAll(list)) // [1, 2, 3, 4, 5, 6, 7]
// High-performance bulk operations
const bigArray = new Array(10000).fill(0).map((_, i) => i)
MutableList.appendAllUnsafe(list, bigArray, true) // Very efficient
appendAllUnsafe(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list, arr: readonly [A, ...A[]](parameter) arr: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<A>;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
find: { (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
arr)
if (const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list.MutableList<in out A>.length: numberlength < chunkSize: numberchunkSize) return const pull: Pull.Pull<
Arr.NonEmptyReadonlyArray<
Arr.NonEmptyReadonlyArray<A>
>,
E | Cause.Done
>
const pull: {
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;
}
pull
let emitted: booleanemitted = true
const const chunks: [
readonly [A, ...A[]],
...(readonly [A, ...A[]])[]
]
const chunks: {
0: readonly [A, ...A[]];
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => readonly [A, ...A[]] | undefined;
push: (...items: Array<readonly [A, ...A[]]>) => number;
concat: { (...items: Array<ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]>; (...items: Array<readonly [A, ...A[]] | ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]> };
join: (separator?: string) => string;
reverse: () => Array<readonly [A, ...A[]]>;
shift: () => readonly [A, ...A[]] | undefined;
slice: (start?: number, end?: number) => Array<readonly [A, ...A[]]>;
sort: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
splice: { (start: number, deleteCount?: number): Array<readonly [A, ...A[]]>; (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]> };
unshift: (...items: Array<readonly [A, ...A[]]>) => number;
indexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
lastIndexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
every: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): this is S[]; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unkn…;
some: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => void, thisArg?: any) => void;
map: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): Array<S>; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown…;
reduce: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
reduceRight: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
find: { (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknow…;
findIndex: (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
fill: (value: readonly [A, ...A[]], start?: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
copyWithin: (target: number, start: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
entries: () => ArrayIterator<[number, readonly [A, ...A[]]]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<readonly [A, ...A[]]>;
includes: (searchElement: readonly [A, ...A[]], fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => readonly [A, ...A[]] | undefined;
findLast: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => un…;
findLastIndex: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
toReversed: () => Array<readonly [A, ...A[]]>;
toSorted: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => Array<readonly [A, ...A[]]>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]>; (start: number, deleteCount?: number): Array<readonly [A, ...A[]]> };
with: (index: number, value: readonly [A, ...A[]]) => Array<readonly [A, ...A[]]>;
}
chunks = [] as any as import ArrArr.type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, chunkSize: number, stepSize: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>A>>
while (const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list.MutableList<in out A>.length: numberlength >= chunkSize: numberchunkSize) {
if (chunkSize: numberchunkSize === stepSize: numberstepSize) {
const chunks: [
readonly [A, ...A[]],
...(readonly [A, ...A[]])[]
]
const chunks: {
0: readonly [A, ...A[]];
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => readonly [A, ...A[]] | undefined;
push: (...items: Array<readonly [A, ...A[]]>) => number;
concat: { (...items: Array<ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]>; (...items: Array<readonly [A, ...A[]] | ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]> };
join: (separator?: string) => string;
reverse: () => Array<readonly [A, ...A[]]>;
shift: () => readonly [A, ...A[]] | undefined;
slice: (start?: number, end?: number) => Array<readonly [A, ...A[]]>;
sort: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
splice: { (start: number, deleteCount?: number): Array<readonly [A, ...A[]]>; (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]> };
unshift: (...items: Array<readonly [A, ...A[]]>) => number;
indexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
lastIndexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
every: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): this is S[]; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unkn…;
some: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => void, thisArg?: any) => void;
map: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): Array<S>; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown…;
reduce: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
reduceRight: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
find: { (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknow…;
findIndex: (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
fill: (value: readonly [A, ...A[]], start?: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
copyWithin: (target: number, start: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
entries: () => ArrayIterator<[number, readonly [A, ...A[]]]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<readonly [A, ...A[]]>;
includes: (searchElement: readonly [A, ...A[]], fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => readonly [A, ...A[]] | undefined;
findLast: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => un…;
findLastIndex: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
toReversed: () => Array<readonly [A, ...A[]]>;
toSorted: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => Array<readonly [A, ...A[]]>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]>; (start: number, deleteCount?: number): Array<readonly [A, ...A[]]> };
with: (index: number, value: readonly [A, ...A[]]) => Array<readonly [A, ...A[]]>;
}
chunks.Array<readonly [A, ...A[]]>.push(...items: (readonly [A, ...A[]])[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(import MutableListMutableList.const takeN: <A>(
self: MutableList<A>,
n: number
) => Array<A>
Takes up to N elements from the beginning of the MutableList and returns them as an array.
The taken elements are removed from the list. This operation is optimized for performance
and includes zero-copy optimizations when possible.
Example (Taking batches)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.appendAll(list, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
console.log(list.length) // 10
// Take first 3 elements
const first3 = MutableList.takeN(list, 3)
console.log(first3) // [1, 2, 3]
console.log(list.length) // 7
// Take more than available
const remaining = MutableList.takeN(list, 20)
console.log(remaining) // [4, 5, 6, 7, 8, 9, 10]
console.log(list.length) // 0
// Take from empty list
const empty = MutableList.takeN(list, 5)
console.log(empty) // []
// Batch processing pattern
const queue = MutableList.make<string>()
MutableList.appendAll(queue, ["task1", "task2", "task3", "task4", "task5"])
while (queue.length > 0) {
const batch = MutableList.takeN(queue, 2) // Process 2 at a time
console.log("Processing batch:", batch)
}
takeN(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list, chunkSize: numberchunkSize) as any)
} else {
const chunks: [
readonly [A, ...A[]],
...(readonly [A, ...A[]])[]
]
const chunks: {
0: readonly [A, ...A[]];
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => readonly [A, ...A[]] | undefined;
push: (...items: Array<readonly [A, ...A[]]>) => number;
concat: { (...items: Array<ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]>; (...items: Array<readonly [A, ...A[]] | ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]> };
join: (separator?: string) => string;
reverse: () => Array<readonly [A, ...A[]]>;
shift: () => readonly [A, ...A[]] | undefined;
slice: (start?: number, end?: number) => Array<readonly [A, ...A[]]>;
sort: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
splice: { (start: number, deleteCount?: number): Array<readonly [A, ...A[]]>; (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]> };
unshift: (...items: Array<readonly [A, ...A[]]>) => number;
indexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
lastIndexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
every: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): this is S[]; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unkn…;
some: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => void, thisArg?: any) => void;
map: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): Array<S>; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown…;
reduce: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
reduceRight: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
find: { (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknow…;
findIndex: (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
fill: (value: readonly [A, ...A[]], start?: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
copyWithin: (target: number, start: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
entries: () => ArrayIterator<[number, readonly [A, ...A[]]]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<readonly [A, ...A[]]>;
includes: (searchElement: readonly [A, ...A[]], fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => readonly [A, ...A[]] | undefined;
findLast: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => un…;
findLastIndex: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
toReversed: () => Array<readonly [A, ...A[]]>;
toSorted: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => Array<readonly [A, ...A[]]>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]>; (start: number, deleteCount?: number): Array<readonly [A, ...A[]]> };
with: (index: number, value: readonly [A, ...A[]]) => Array<readonly [A, ...A[]]>;
}
chunks.Array<readonly [A, ...A[]]>.push(...items: (readonly [A, ...A[]])[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(import MutableListMutableList.const toArrayN: <A>(
self: MutableList<A>,
n: number
) => Array<A>
Copies up to n elements from the beginning of the MutableList into a new
array without modifying the list.
When to use
Use when you need to inspect or snapshot a bounded prefix of the list without
consuming it.
toArrayN(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list, chunkSize: numberchunkSize) as any)
if (chunkSize: numberchunkSize === 1) {
import MutableListMutableList.const take: <A>(
self: MutableList<A>
) => Empty | A
Takes a single element from the beginning of the MutableList.
Returns the element if available, or the Empty symbol if the list is empty.
The taken element is removed from the list.
Example (Taking one element)
import { MutableList } from "effect"
const list = MutableList.make<string>()
MutableList.appendAll(list, ["first", "second", "third"])
// Take elements one by one
console.log(MutableList.take(list)) // "first"
console.log(list.length) // 2
console.log(MutableList.take(list)) // "second"
console.log(MutableList.take(list)) // "third"
console.log(list.length) // 0
// Take from empty list
console.log(MutableList.take(list)) // Empty symbol
// Check for empty using the Empty symbol
const result = MutableList.take(list)
if (result === MutableList.Empty) {
console.log("List is empty")
} else {
console.log("Got element:", result)
}
// Consumer pattern
function processNext<T>(
queue: MutableList.MutableList<T>,
processor: (item: T) => void
): boolean {
const item = MutableList.take(queue)
if (item !== MutableList.Empty) {
processor(item)
return true
}
return false
}
take(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list)
} else {
import MutableListMutableList.const takeNVoid: <A>(
self: MutableList<A>,
n: number
) => void
Removes up to n elements from the beginning of the MutableList without
returning them.
When to use
Use to discard a bounded number of values from the head of a MutableList
when the removed values are not needed.
Details
If n is less than or equal to zero, or the list is empty, the list is left
unchanged. If n is greater than or equal to the current length, the list is
cleared.
takeNVoid(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list, stepSize: numberstepSize)
}
}
}
return import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(const chunks: [
readonly [A, ...A[]],
...(readonly [A, ...A[]])[]
]
const chunks: {
0: readonly [A, ...A[]];
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => readonly [A, ...A[]] | undefined;
push: (...items: Array<readonly [A, ...A[]]>) => number;
concat: { (...items: Array<ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]>; (...items: Array<readonly [A, ...A[]] | ConcatArray<readonly [A, ...A[]]>>): Array<readonly [A, ...A[]]> };
join: (separator?: string) => string;
reverse: () => Array<readonly [A, ...A[]]>;
shift: () => readonly [A, ...A[]] | undefined;
slice: (start?: number, end?: number) => Array<readonly [A, ...A[]]>;
sort: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
splice: { (start: number, deleteCount?: number): Array<readonly [A, ...A[]]>; (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]> };
unshift: (...items: Array<readonly [A, ...A[]]>) => number;
indexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
lastIndexOf: (searchElement: readonly [A, ...A[]], fromIndex?: number) => number;
every: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): this is S[]; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unkn…;
some: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => void, thisArg?: any) => void;
map: (callbackfn: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): Array<S>; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown…;
reduce: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
reduceRight: { (callbackfn: (previousValue: readonly [A, ...A[]], currentValue: readonly [A, ...A[]], currentIndex: number, array: Array<readonly [A, ...A[]]>) => readonly [A, ...A[]]): readonly [A, ...A[]]; (callbackfn: (previousValue: readonly [A, ..…;
find: { (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknow…;
findIndex: (predicate: (value: readonly [A, ...A[]], index: number, obj: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
fill: (value: readonly [A, ...A[]], start?: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
copyWithin: (target: number, start: number, end?: number) => [readonly [A, ...A[]], ...(readonly [A, ...A[]])[]];
entries: () => ArrayIterator<[number, readonly [A, ...A[]]]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<readonly [A, ...A[]]>;
includes: (searchElement: readonly [A, ...A[]], fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => readonly [A, ...A[]] | undefined;
findLast: { (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => value is S, thisArg?: any): S | undefined; (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => un…;
findLastIndex: (predicate: (value: readonly [A, ...A[]], index: number, array: Array<readonly [A, ...A[]]>) => unknown, thisArg?: any) => number;
toReversed: () => Array<readonly [A, ...A[]]>;
toSorted: (compareFn?: ((a: readonly [A, ...A[]], b: readonly [A, ...A[]]) => number) | undefined) => Array<readonly [A, ...A[]]>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<readonly [A, ...A[]]>): Array<readonly [A, ...A[]]>; (start: number, deleteCount?: number): Array<readonly [A, ...A[]]> };
with: (index: number, value: readonly [A, ...A[]]) => Array<readonly [A, ...A[]]>;
}
chunks)
},
onFailure: (
cause: Cause.Cause<Cause.Done<void> | E>
) => Effect.Effect<
[any, ...any[]],
Cause.Done<void> | E,
never
>
onFailure(cause_: Cause.Cause<Cause.Done<void> | 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_) {
if (let emitted: booleanemitted) import MutableListMutableList.const takeNVoid: <A>(
self: MutableList<A>,
n: number
) => void
Removes up to n elements from the beginning of the MutableList without
returning them.
When to use
Use to discard a bounded number of values from the head of a MutableList
when the removed values are not needed.
Details
If n is less than or equal to zero, or the list is empty, the list is left
unchanged. If n is greater than or equal to the current length, the list is
cleared.
takeNVoid(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list, chunkSize: numberchunkSize - stepSize: numberstepSize)
if (const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list.MutableList<in out A>.length: numberlength === 0) return import EffectEffect.const failCause: <E>(
cause: Cause.Cause<E>
) => Effect<never, E>
Creates an Effect that represents a failure with a specific Cause.
When to use
Use when you already have a full Cause and need to preserve defects,
interruptions, annotations, or combined failures in the effect's failure
channel.
Details
This function allows you to create effects that fail with complex error
structures, including multiple errors, defects, interruptions, and more.
Example (Failing with a full Cause)
import { Cause, Effect } from "effect"
const program = Effect.failCause(
Cause.fail("Network error")
)
Effect.runPromiseExit(program).then(console.log)
// Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
failCause(cause_: Cause.Cause<Cause.Done<void> | 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_)
let cause: Cause.Cause<
E | Cause.Done
> | null
cause = cause_: Cause.Cause<Cause.Done<void> | 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_
return import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(import ArrArr.const of: <A>(a: A) => NonEmptyArray<A>Wraps a single value in a NonEmptyArray.
Example (Creating a single-element array)
import { Array } from "effect"
console.log(Array.of(1)) // [1]
of(import MutableListMutableList.const takeAll: <A>(
self: MutableList<A>
) => Array<A>
Takes all elements from the MutableList and returns them as an array.
The list becomes empty after this operation. This is equivalent to takeN(list, list.length).
Example (Draining all elements)
import { MutableList } from "effect"
const list = MutableList.make<string>()
MutableList.appendAll(list, ["apple", "banana", "cherry"])
console.log(list.length) // 3
// Take all elements
const allItems = MutableList.takeAll(list)
console.log(allItems) // ["apple", "banana", "cherry"]
console.log(list.length) // 0
// Useful for converting to array and clearing
const queue = MutableList.make<number>()
MutableList.appendAll(queue, [1, 2, 3, 4, 5])
const snapshot = MutableList.takeAll(queue)
console.log("Queue contents:", snapshot)
console.log("Queue is now empty:", queue.length === 0)
// Drain pattern for processing
function drainAndProcess<T>(
list: MutableList.MutableList<T>,
processor: (items: Array<T>) => void
) {
if (list.length > 0) {
const items = MutableList.takeAll(list)
processor(items)
}
}
takeAll(const list: MutableList.MutableList<A>const list: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
list) as any))
}
})
return import EffectEffect.const suspend: <A, E, R>(
effect: LazyArg<Effect<A, E, R>>
) => Effect<A, E, R>
Creates an Effect lazily, delaying construction until it is needed.
When to use
Use when you need to defer the evaluation of an effect until it is required.
Details
suspend takes a thunk that represents an effect and delays creating it
until the suspended effect is evaluated. This is useful for optimizing
expensive computations, managing circular dependencies such as recursive
functions, and helping TypeScript unify return types when branches construct
different effects. Any side effects or scoped captures inside the thunk are
re-executed on each invocation.
Example (Lazily evaluating side effects)
import { Effect } from "effect"
let i = 0
const bad = Effect.succeed(i++)
const good = Effect.suspend(() => Effect.succeed(i++))
console.log(Effect.runSync(bad)) // Output: 0
console.log(Effect.runSync(bad)) // Output: 0
console.log(Effect.runSync(good)) // Output: 1
console.log(Effect.runSync(good)) // Output: 2
Example (Suspending recursive Fibonacci evaluation)
import { Effect } from "effect"
const blowsUp = (n: number): Effect.Effect<number> =>
n < 2
? Effect.succeed(1)
: Effect.zipWith(blowsUp(n - 1), blowsUp(n - 2), (a, b) => a + b)
// console.log(Effect.runSync(blowsUp(32)))
// crash: JavaScript heap out of memory
const allGood = (n: number): Effect.Effect<number> =>
n < 2
? Effect.succeed(1)
: Effect.zipWith(
Effect.suspend(() => allGood(n - 1)),
Effect.suspend(() => allGood(n - 2)),
(a, b) => a + b
)
console.log(Effect.runSync(allGood(32)))
// Output: 3524578
Example (Helping TypeScript infer recursive effect types)
import { Effect } from "effect"
// Without suspend, TypeScript may struggle with type inference.
// Inferred type:
// (a: number, b: number) =>
// Effect<never, Error, never> | Effect<number, never, never>
const withoutSuspend = (a: number, b: number) =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// Using suspend to unify return types.
// Inferred type:
// (a: number, b: number) => Effect<number, Error, never>
const withSuspend = (a: number, b: number) =>
Effect.suspend(() =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
)
suspend(() => let cause: Cause.Cause<
E | Cause.Done
> | null
cause ? import EffectEffect.const failCause: <E>(
cause: Cause.Cause<E>
) => Effect<never, E>
Creates an Effect that represents a failure with a specific Cause.
When to use
Use when you already have a full Cause and need to preserve defects,
interruptions, annotations, or combined failures in the effect's failure
channel.
Details
This function allows you to create effects that fail with complex error
structures, including multiple errors, defects, interruptions, and more.
Example (Failing with a full Cause)
import { Cause, Effect } from "effect"
const program = Effect.failCause(
Cause.fail("Network error")
)
Effect.runPromiseExit(program).then(console.log)
// Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
failCause(let cause: Cause.Cause<
E | Cause.Done
> | null
let 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) : const pull: Pull.Pull<
Arr.NonEmptyReadonlyArray<
Arr.NonEmptyReadonlyArray<A>
>,
E | Cause.Done
>
const pull: {
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;
}
pull)
}))
)