<const N extends number>(
options:
| {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
readonly replay?: number | undefined
}
): <A, E, R>(
self: Stream<A, E, R>
) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
<A, E, R, const N extends number>(
self: Stream<A, E, R>,
options:
| {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly n: N
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
readonly replay?: number | undefined
}
): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>Creates a fixed-size tuple of streams that each emit the same elements as the source stream.
Details
The source stream starts after all downstream streams have been subscribed.
With the default suspend strategy, the source can only advance capacity
chunks ahead of the slowest downstream stream. If a downstream stream is
interrupted, it unsubscribes from the broadcast so it no longer contributes
backpressure.
Example (Broadcasting to two consumers)
import { Console, Effect, Stream } from "effect"
const program = Effect.scoped(
Effect.gen(function*() {
const [left, right] = yield* Stream.make(1, 2, 3).pipe(
Stream.broadcastN({ n: 2, capacity: 8 })
)
const values = yield* Effect.all([
Stream.runCollect(left),
Stream.runCollect(right)
], { concurrency: "unbounded" })
yield* Console.log(values)
})
)
Effect.runPromise(program)
// Output: [[1, 2, 3], [1, 2, 3]]export const const broadcastN: {
<N extends number>(
options:
| {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
): <A, E, R>(
self: Stream<A, E, R>
) => Effect.Effect<
TupleOf<N, Stream<A, E>>,
never,
Scope.Scope | R
>
<A, E, R, N extends number>(
self: Stream<A, E, R>,
options:
| {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly n: N
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
): Effect.Effect<
TupleOf<N, Stream<A, E>>,
never,
Scope.Scope | R
>
}
Creates a fixed-size tuple of streams that each emit
the same elements as the source stream.
Details
The source stream starts after all downstream streams have been subscribed.
With the default suspend strategy, the source can only advance capacity
chunks ahead of the slowest downstream stream. If a downstream stream is
interrupted, it unsubscribes from the broadcast so it no longer contributes
backpressure.
Example (Broadcasting to two consumers)
import { Console, Effect, Stream } from "effect"
const program = Effect.scoped(
Effect.gen(function*() {
const [left, right] = yield* Stream.make(1, 2, 3).pipe(
Stream.broadcastN({ n: 2, capacity: 8 })
)
const values = yield* Effect.all([
Stream.runCollect(left),
Stream.runCollect(right)
], { concurrency: "unbounded" })
yield* Console.log(values)
})
)
Effect.runPromise(program)
// Output: [[1, 2, 3], [1, 2, 3]]
broadcastN: {
<const function (type parameter) N in <const N extends number>(options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N extends number>(
options: | {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options: {
readonly n: const N extends numbern: function (type parameter) N in <const N extends number>(options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N
readonly capacity: "unbounded"capacity: "unbounded"
readonly replay?: number | undefinedreplay?: number | undefined
} | {
readonly n: const N extends numbern: function (type parameter) N in <const N extends number>(options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N
readonly capacity: numbercapacity: number
readonly strategy?: | "sliding"
| "dropping"
| "suspend"
| undefined
strategy?: "sliding" | "dropping" | "suspend" | undefined
readonly replay?: number | undefinedreplay?: number | undefined
}
): <function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | 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>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>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<type TupleOf<N extends number, T> = N extends N ? number extends N ? T[] : TupleOf_<T, N, []> : neverConstructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
- If
N is a literal number, produces a tuple of that exact length.
- If
N is the general number type (non-literal), degrades to Array<T>.
- Negative numbers produce
never.
Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
//
TupleOf<function (type parameter) N in <const N extends number>(options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N, 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>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>E>>, never, import ScopeScope.Scope | function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>R>
<function (type parameter) A in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
E, function (type parameter) R in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
R, const function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N extends number>(
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, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
E, function (type parameter) R in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
R>,
options: | {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly n: N
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options: {
readonly n: const N extends numbern: function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N
readonly capacity: "unbounded"capacity: "unbounded"
readonly replay?: number | undefinedreplay?: number | undefined
} | {
readonly capacity: numbercapacity: number
readonly n: const N extends numbern: function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N
readonly strategy?: | "sliding"
| "dropping"
| "suspend"
| undefined
strategy?: "sliding" | "dropping" | "suspend" | undefined
readonly replay?: number | undefinedreplay?: number | undefined
}
): 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<type TupleOf<N extends number, T> = N extends N ? number extends N ? T[] : TupleOf_<T, N, []> : neverConstructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
- If
N is a literal number, produces a tuple of that exact length.
- If
N is the general number type (non-literal), degrades to Array<T>.
- Negative numbers produce
never.
Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
//
TupleOf<function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
N, 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, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
E>>, never, import ScopeScope.Scope | function (type parameter) R in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly n: N;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
R>
} = dual<(...args: Array<any>) => any, <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<TupleOf<N, Stream<A, E, never>>, never, Scope.Scope | R>>(arity: 2, body: <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<TupleOf<N, Stream<A, E, never>>, never, Scope.Scope | R>): ((...args: Array<any>) => any) & (<A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<TupleOf<N, Stream<A, E, never>>, never, Scope.Scope | 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(
2,
import EffectEffect.const fnUntraced: <Effect.Effect<Scope.Scope, never, Scope.Scope> | Effect.Effect<PubSub.PubSub<Take.Take<A, E, void>>, never, Scope.Scope> | Effect.Effect<PubSub.Subscription<Take.Take<A, E, void>>, never, never> | Effect.Effect<Fiber.Fiber<void, E>, never, Scope.Scope | R>, TupleOf<N, Stream<A, E, never>>, [self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
...;
}]>(body: (this: unassigned, self: Stream<...>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
...;
}) => Generator<...>) => <A, E, R, const N extends number>(self: Stream<...>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
...;
}) => Effect.Effect<...> (+41 overloads)
fnUntraced(function*<function (type parameter) A in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
E, function (type parameter) R in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
R, const function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
N extends number>(
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, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
E, function (type parameter) R in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
R>,
options: | {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options: {
readonly n: const N extends numbern: function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
N
readonly capacity: "unbounded"capacity: "unbounded"
readonly replay?: number | undefinedreplay?: number | undefined
} | {
readonly n: const N extends numbern: function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
N
readonly capacity: numbercapacity: number
readonly strategy?: | "sliding"
| "dropping"
| "suspend"
| undefined
strategy?: "sliding" | "dropping" | "suspend" | undefined
readonly replay?: number | undefinedreplay?: number | undefined
}
) {
const const pubsub: PubSub.PubSub<
Take.Take<A, E, void>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<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; <…;
}
pubsub = yield* const makePubSub: <Take.Take<A, E, void>>(options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<PubSub.PubSub<Take.Take<A, E, void>>, never, Scope.Scope>
makePubSub<import TakeTake.type Take<A, E = never, Done = void> =
| readonly [A, ...A[]]
| Exit.Exit<Done, E>
Represents one pull result: either a non-empty batch of values, a failure
Exit, or a successful Exit that signals completion with a Done value.
When to use
Use to store, transfer, or interpret pull results later while preserving
emitted values, failures, and normal completion.
Take<function (type parameter) A in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
E>>(options: | {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options)
const const streams: any[]streams = new var Array: ArrayConstructor
new (arrayLength?: number) => any[] (+2 overloads)
Array(options: | {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options.n: const N extends numbern)
const const parentScope: Scope.Scopeconst parentScope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
parentScope = yield* import ScopeScope.const Scope: Context.Service<Scope, Scope>const Scope: {
key: string;
Service: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
};
of: (this: void, self: Scope.Scope) => Scope.Scope;
context: (self: Scope.Scope) => Context.Context<Scope.Scope>;
use: (f: (service: Scope.Scope) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Scope.Scope | R>;
useSync: (f: (service: Scope.Scope) => A) => Effect.Effect<A, never, Scope.Scope>;
Identifier: Identifier;
stack: string | undefined;
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;
}
A Scope represents a context where resources can be acquired and
automatically cleaned up when the scope is closed. Scopes can use
either sequential or parallel finalization strategies.
Example (Managing scoped resources)
import { Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Scope has a strategy and state
console.log(scope.strategy) // "sequential"
console.log(scope.state._tag) // "Open"
// Close the scope
yield* Scope.close(scope, Exit.void)
console.log(scope.state._tag) // "Closed"
})
Service tag for the active resource lifetime.
When to use
Use to access the active lifetime when registering finalizers or sharing
resources with the surrounding scope.
Example (Accessing the scope service)
import { Effect, Scope } from "effect"
const program = Effect.gen(function*() {
// Access the scope from the context
const scope = yield* Scope.Scope
// Use the scope for resource management
yield* Scope.addFinalizer(scope, Effect.log("Cleanup"))
})
// Provide a scope to the program
const scoped = Effect.scoped(program)
Scope
for (let let i: numberi = 0; let i: numberi < options: | {
readonly n: N
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly n: N
readonly capacity: number
readonly strategy?:
| "sliding"
| "dropping"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options.n: const N extends numbern; let i: numberi++) {
const const scope: Scope.Closeableconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope = import ScopeScope.const forkUnsafe: (
scope: Scope,
finalizerStrategy?: "sequential" | "parallel"
) => Closeable
Creates a closeable child scope synchronously and registers it with a parent scope.
When to use
Use when a child scope must be created synchronously and the caller controls
both parent and child scope lifetimes.
Details
Closing the parent closes the child with the same exit value, and closing the
child detaches it from the parent. The optional finalizer strategy configures
the child scope and defaults to "sequential" when omitted.
Example (Creating a child scope synchronously)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const parentScope = Scope.makeUnsafe("sequential")
const childScope = Scope.forkUnsafe(parentScope, "parallel")
// Add finalizers to both scopes
yield* Scope.addFinalizer(parentScope, Console.log("Parent cleanup"))
yield* Scope.addFinalizer(childScope, Console.log("Child cleanup"))
// Close child first, then parent
yield* Scope.close(childScope, Exit.void)
yield* Scope.close(parentScope, Exit.void)
})
forkUnsafe(const parentScope: Scope.Scopeconst parentScope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
parentScope)
const const subscription: PubSub.Subscription<
Take.Take<A, E, void>
>
const subscription: {
pubsub: PubSub.Atomic<any>;
subscribers: PubSub.Subscribers<any>;
subscription: PubSub.BackingSubscription<A>;
pollers: MutableList.MutableList<Deferred.Deferred<any>>;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<any>;
replayWindow: PubSub.ReplayWindow<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; <…;
}
subscription = yield* import PubSubPubSub.const subscribe: <A>(
self: PubSub<A>
) => Effect.Effect<
Subscription<A>,
never,
Scope.Scope
>
Subscribes to receive messages from the PubSub. The resulting subscription can
be evaluated multiple times within the scope to take a message from the PubSub
each time.
Example (Subscribing to messages)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
// Subscribe within a scope for automatic cleanup
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Publish some messages
yield* PubSub.publish(pubsub, "Hello")
yield* PubSub.publish(pubsub, "World")
// Take messages one by one
const msg1 = yield* PubSub.take(subscription)
const msg2 = yield* PubSub.take(subscription)
console.log(msg1, msg2) // "Hello", "World"
// Subscription is automatically cleaned up when scope exits
}))
yield* Effect.scoped(Effect.gen(function*() {
const sub1 = yield* PubSub.subscribe(pubsub)
const sub2 = yield* PubSub.subscribe(pubsub)
// Multiple subscribers can receive the same messages
yield* PubSub.publish(pubsub, "Broadcast")
const [msg1, msg2] = yield* Effect.all([
PubSub.take(sub1),
PubSub.take(sub2)
])
console.log("Both received:", msg1, msg2) // "Broadcast", "Broadcast"
}))
})
subscribe(const pubsub: PubSub.PubSub<
Take.Take<A, E, void>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<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; <…;
}
pubsub).Pipeable.pipe<Effect.Effect<PubSub.Subscription<Take.Take<A, E, void>>, never, Scope.Scope>, Effect.Effect<PubSub.Subscription<Take.Take<A, E, void>>, never, never>>(this: Effect.Effect<PubSub.Subscription<Take.Take<A, E, void>>, never, Scope.Scope>, ab: (_: Effect.Effect<PubSub.Subscription<Take.Take<A, E, void>>, never, Scope.Scope>) => Effect.Effect<PubSub.Subscription<Take.Take<A, E, void>>, never, never>): Effect.Effect<...> (+21 overloads)pipe(
import EffectEffect.const provideService: {
<I, S>(service: Context.Key<I, S>): {
(implementation: S): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, I>>
<A, E, R>(
self: Effect<A, E, R>,
implementation: S
): Effect<A, E, Exclude<R, I>>
}
<I, S>(
service: Context.Key<I, S>,
implementation: S
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, I>>
<A, E, R, I, S>(
self: Effect<A, E, R>,
service: Context.Key<I, S>,
implementation: S
): Effect<A, E, Exclude<R, I>>
}
provideService(import ScopeScope.const Scope: Context.Service<Scope, Scope>const Scope: {
key: string;
Service: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
};
of: (this: void, self: Scope.Scope) => Scope.Scope;
context: (self: Scope.Scope) => Context.Context<Scope.Scope>;
use: (f: (service: Scope.Scope) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Scope.Scope | R>;
useSync: (f: (service: Scope.Scope) => A) => Effect.Effect<A, never, Scope.Scope>;
Identifier: Identifier;
stack: string | undefined;
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;
}
A Scope represents a context where resources can be acquired and
automatically cleaned up when the scope is closed. Scopes can use
either sequential or parallel finalization strategies.
Example (Managing scoped resources)
import { Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Scope has a strategy and state
console.log(scope.strategy) // "sequential"
console.log(scope.state._tag) // "Open"
// Close the scope
yield* Scope.close(scope, Exit.void)
console.log(scope.state._tag) // "Closed"
})
Service tag for the active resource lifetime.
When to use
Use to access the active lifetime when registering finalizers or sharing
resources with the surrounding scope.
Example (Accessing the scope service)
import { Effect, Scope } from "effect"
const program = Effect.gen(function*() {
// Access the scope from the context
const scope = yield* Scope.Scope
// Use the scope for resource management
yield* Scope.addFinalizer(scope, Effect.log("Cleanup"))
})
// Provide a scope to the program
const scoped = Effect.scoped(program)
Scope, const scope: Scope.Closeableconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope)
)
const streams: any[]streams[let i: numberi] = import ChannelChannel.const fromEffectTake: <A, E, Done, E2, R>(
effect: Effect.Effect<
Take.Take<A, E, Done>,
E2,
R
>
) => Channel<
Arr.NonEmptyReadonlyArray<A>,
E | E2,
Done,
unknown,
unknown,
unknown,
R
>
Creates a channel from an effect that produces a Take.
Details
A successful Take emits a non-empty array of output elements. A failed
Take fails the channel. A done Take completes the channel with its done
value.
fromEffectTake(import PubSubPubSub.const take: <A>(
self: Subscription<A>
) => Effect.Effect<A>
Takes a single message from the subscription. If no messages are available,
this will suspend until a message becomes available.
Example (Taking a message)
import { Effect, Fiber, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Start a fiber to take a message (will suspend)
const takeFiber = yield* Effect.forkChild(
PubSub.take(subscription)
)
// Publish a message
yield* PubSub.publish(pubsub, "Hello")
// The take will now complete
const message = yield* Fiber.join(takeFiber)
console.log("Received:", message) // "Hello"
}))
})
take(const subscription: PubSub.Subscription<
Take.Take<A, E, void>
>
const subscription: {
pubsub: PubSub.Atomic<any>;
subscribers: PubSub.Subscribers<any>;
subscription: PubSub.BackingSubscription<A>;
pollers: MutableList.MutableList<Deferred.Deferred<any>>;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<any>;
replayWindow: PubSub.ReplayWindow<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; <…;
}
subscription)).Pipeable.pipe<Channel.Channel<readonly [A, ...A[]], E, void, unknown, unknown, unknown, never>, Channel.Channel<readonly [A, ...A[]], E, void, unknown, unknown, unknown, never>, Stream<A, E, never>>(this: Channel.Channel<readonly [A, ...A[]], E, void, unknown, unknown, unknown, never>, ab: (_: Channel.Channel<readonly [A, ...A[]], E, void, unknown, unknown, unknown, never>) => Channel.Channel<readonly [A, ...A[]], E, void, unknown, unknown, unknown, never>, bc: (_: Channel.Channel<readonly [A, ...A[]], E, void, unknown, unknown, unknown, never>) => Stream<A, E, never>): Stream<A, E, never> (+21 overloads)pipe(
import ChannelChannel.const onExit: {
<OutDone, OutErr, Env2>(
finalizer: (
e: Exit.Exit<OutDone, OutErr>
) => Effect.Effect<unknown, never, Env2>
): <OutElem, InElem, InErr, InDone, Env>(
self: Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>
) => Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env2 | Env
>
<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env,
Env2
>(
self: Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>,
finalizer: (
e: Exit.Exit<OutDone, OutErr>
) => Effect.Effect<unknown, never, Env2>
): Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env2 | Env
>
}
onExit((exit: Exit.Exit<void, E>exit) => 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, exit: Exit.Exit<void, E>exit)),
const fromChannel: <
Arr extends Arr.NonEmptyReadonlyArray<any>,
E,
R
>(
channel: Channel.Channel<
Arr,
E,
void,
unknown,
unknown,
unknown,
R
>
) => Stream<
Arr extends Arr.NonEmptyReadonlyArray<infer A>
? A
: never,
E,
R
>
Creates a stream from a array-emitting Channel.
Example (Creating a stream from an array-emitting channel)
import { Channel, Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const channel = Channel.succeed([1, 2, 3] as const)
const stream = Stream.fromChannel(channel)
const result = yield* Stream.runCollect(stream)
yield* Console.log(result)
})
// Output: [ 1, 2, 3 ]
fromChannel
)
}
yield* import ChannelChannel.const runForEach: {
<OutElem, EX, RX>(
f: (o: OutElem) => Effect.Effect<void, EX, RX>
): <OutErr, OutDone, Env>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
) => Effect.Effect<
OutDone,
OutErr | EX,
Env | RX
>
<OutElem, OutErr, OutDone, Env, EX, RX>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>,
f: (o: OutElem) => Effect.Effect<void, EX, RX>
): Effect.Effect<OutDone, OutErr | EX, Env | RX>
}
runForEach(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.Stream<A, E, R>.channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>(property) Stream<A, E, R>.channel: {
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; <…;
}
channel, (value: readonly [A, ...A[]](parameter) value: {
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>;
}
value) => import PubSubPubSub.const publish: {
<A>(value: A): (
self: PubSub<A>
) => Effect.Effect<boolean>
<A>(
self: PubSub<A>,
value: A
): Effect.Effect<boolean>
}
publish(const pubsub: PubSub.PubSub<
Take.Take<A, E, void>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<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; <…;
}
pubsub, value: readonly [A, ...A[]](parameter) value: {
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>;
}
value)).Pipeable.pipe<Effect.Effect<void, E, R>, Effect.Effect<void, E, R>, Effect.Effect<Fiber.Fiber<void, E>, never, Scope.Scope | R>>(this: Effect.Effect<void, E, R>, ab: (_: Effect.Effect<void, E, R>) => Effect.Effect<void, E, R>, bc: (_: Effect.Effect<void, E, R>) => Effect.Effect<Fiber.Fiber<void, E>, never, Scope.Scope | R>): Effect.Effect<Fiber.Fiber<void, E>, never, Scope.Scope | R> (+21 overloads)pipe(
import EffectEffect.const onExit: {
<A, E, XE = never, XR = never>(
f: (
exit: Exit.Exit<A, E>
) => Effect<void, XE, XR>
): <R>(
self: Effect<A, E, R>
) => Effect<A, E | XE, R | XR>
<A, E, R, XE = never, XR = never>(
self: Effect<A, E, R>,
f: (
exit: Exit.Exit<A, E>
) => Effect<void, XE, XR>
): Effect<A, E | XE, R | XR>
}
onExit((exit: Exit.Exit<void, E>exit) => import PubSubPubSub.const publish: {
<A>(value: A): (
self: PubSub<A>
) => Effect.Effect<boolean>
<A>(
self: PubSub<A>,
value: A
): Effect.Effect<boolean>
}
publish(const pubsub: PubSub.PubSub<
Take.Take<A, E, void>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<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; <…;
}
pubsub, exit: Exit.Exit<void, E>exit)),
import EffectEffect.const forkScoped: <
Arg extends
| Effect<any, any, any>
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined = {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
>(
effectOrOptions?: Arg,
options?:
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined
) => [Arg] extends [
Effect<infer _A, infer _E, infer _R>
]
? Effect<Fiber<_A, _E>, never, _R | Scope>
: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Fiber<A, E>, never, R | Scope>
Forks the fiber in a Scope, interrupting it when the scope is closed.
Example (Forking into the current scope)
import { Effect } from "effect"
const backgroundTask = Effect.gen(function*() {
yield* Effect.sleep("5 seconds")
yield* Effect.log("Background task completed")
return "result"
})
const program = Effect.scoped(
Effect.gen(function*() {
const fiber = yield* backgroundTask.pipe(Effect.forkScoped)
// or fork a fiber that starts immediately:
yield* backgroundTask.pipe(Effect.forkScoped({ startImmediately: true }))
yield* Effect.log("Task forked in scope")
yield* Effect.sleep("1 second")
// Fiber will be interrupted when scope closes
return "scope completed"
})
)
forkScoped
)
return const streams: any[]streams as type TupleOf<N extends number, T> = N extends N ? number extends N ? T[] : TupleOf_<T, N, []> : neverConstructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
- If
N is a literal number, produces a tuple of that exact length.
- If
N is the general number type (non-literal), degrades to Array<T>.
- Negative numbers produce
never.
Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
//
TupleOf<function (type parameter) N in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
N, 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, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
A, function (type parameter) E in <A, E, R, const N extends number>(self: Stream<A, E, R>, options: {
readonly n: N;
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly n: N;
readonly capacity: number;
readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
E>>
})
)