<A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(
handlers: Cases
): (
self: Stream.Stream<A>
) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>
<A extends TaggedEvent, const K extends A["_tag"], E, R>(
tag: K,
f: (
event: Extract<A, { readonly _tag: K }>
) => Effect.Effect<void, E, R>
): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
<A extends TaggedEvent, const K extends A["_tag"], E, R>(
self: Stream.Stream<A>,
tag: K,
f: (
event: Extract<A, { readonly _tag: K }>
) => Effect.Effect<void, E, R>
): Effect.Effect<void, E, R>
<A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(
self: Stream.Stream<A>,
handlers: Cases
): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Consume a tagged-event Stream, dispatching each element to a handler by its _tag —
the stream-native replacement for lifecycle callbacks (one off-fiber consumer, not a fiber
per item). Pass a single tag + handler or a handler map; data-first or pipeable.
Built on Match, so handlers are fully typed with no casts; unhandled tags are ignored.
yield* jobs.events.pipe(Hyperlink.runForEachTag({
Failed: ({ entry, cause }) => Effect.logError(`failed ${entry.entryId}`, cause),
Drained: ({ completed }) => Effect.log(`drained @ ${completed}`),
}))
yield* Hyperlink.runForEachTag(jobs.events, "Failed", (e) =>
Effect.failCause(e.cause).pipe(Effect.catchTags({ Timeout: …, Rejected: … })),
)export const const runForEachTag: {
<
A extends TaggedEvent,
Cases extends TagHandlers<A, unknown, unknown>
>(
handlers: Cases
): (
self: Stream.Stream<A>
) => Effect.Effect<
void,
HandlersError<Cases>,
HandlersContext<Cases>
>
<
A extends TaggedEvent,
K extends A["_tag"],
E,
R
>(
tag: K,
f: (
event: Extract<A, { readonly _tag: K }>
) => Effect.Effect<void, E, R>
): (
self: Stream.Stream<A>
) => Effect.Effect<void, E, R>
<
A extends TaggedEvent,
K extends A["_tag"],
E,
R
>(
self: Stream.Stream<A>,
tag: K,
f: (
event: Extract<A, { readonly _tag: K }>
) => Effect.Effect<void, E, R>
): Effect.Effect<void, E, R>
<
A extends TaggedEvent,
Cases extends TagHandlers<A, unknown, unknown>
>(
self: Stream.Stream<A>,
handlers: Cases
): Effect.Effect<
void,
HandlersError<Cases>,
HandlersContext<Cases>
>
}
Consume a tagged-event
Stream
, dispatching each element to a handler by its _tag —
the stream-native replacement for lifecycle callbacks (one off-fiber consumer, not a fiber
per item). Pass a single tag + handler or a handler map; data-first or pipeable.
Built on Match, so handlers are fully typed with no casts; unhandled tags are ignored.
yield* jobs.events.pipe(Hyperlink.runForEachTag({
Failed: ({ entry, cause }) => Effect.logError(`failed ${entry.entryId}`, cause),
Drained: ({ completed }) => Effect.log(`drained @ ${completed}`),
}))
yield* Hyperlink.runForEachTag(jobs.events, "Failed", (e) =>
Effect.failCause(e.cause).pipe(Effect.catchTags({ Timeout: …, Rejected: … })),
)
runForEachTag: {
// ── data-last (pipeable) ──
// `Cases` is inferred from the literal; E/R are EXTRACTED from the handlers via `infer`
// (not inferrable params), so `A` can unify at the pipe site without dragging R to `unknown`.
<
function (type parameter) A in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>A extends type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent,
function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases extends type TagHandlers<
A extends TaggedEvent,
E,
R
> = {
[P in keyof {
readonly [K in A["_tag"]]: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
}]?:
| {
readonly [K in A["_tag"]]: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
}[P]
| undefined
}
A partial set of per-_tag handlers over a tagged-event union — the handler-map form of
Hyperlink.runForEachTag
. Each handler receives the narrowed event for its tag.
TagHandlers<function (type parameter) A in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>A, unknown, unknown>,
>(
handlers: Cases extends TagHandlers<A, unknown, unknown>handlers: function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases,
): (
self: Stream.Stream<A, never, never>(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: import StreamStream.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 extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>A>,
) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, type HandlersError<Cases> = {
[K in keyof Cases]: Cases[K] extends (
event: never
) => Effect.Effect<unknown, infer E, unknown>
? E
: never
}[keyof Cases]
The union of every handler's error channel (extracted via infer, like Effect.catchTags).
HandlersError<function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases>, type HandlersContext<Cases> = {
[K in keyof Cases]: Cases[K] extends (
event: never
) => Effect.Effect<unknown, unknown, infer R>
? R
: never
}[keyof Cases]
The union of every handler's requirement channel — so R doesn't leak to unknown.
HandlersContext<function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases>>;
<function (type parameter) A in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
A extends type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent, const function (type parameter) K in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
K extends function (type parameter) A in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
A["_tag"], function (type parameter) E in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
E, function (type parameter) R in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
R>(
tag: const K extends A["_tag"]tag: function (type parameter) K in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
K,
f: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
f: (event: Extract<
A,
{
readonly _tag: K
}
>
event: type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) A in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
A, { readonly _tag: const K extends A["_tag"]_tag: function (type parameter) K in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
K }>) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, function (type parameter) E in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
E, function (type parameter) R in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
R>,
): (self: Stream.Stream<A, never, never>(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: import StreamStream.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 extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
A>) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, function (type parameter) E in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
E, function (type parameter) R in <A extends TaggedEvent, const K extends A["_tag"], E, R>(tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): (self: Stream.Stream<A>) => Effect.Effect<void, E, R>
R>;
// ── data-first ──
<function (type parameter) A in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
A extends type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent, const function (type parameter) K in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
K extends function (type parameter) A in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
A["_tag"], function (type parameter) E in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
E, function (type parameter) R in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
R>(
self: Stream.Stream<A, never, never>(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: import StreamStream.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 extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
A>,
tag: const K extends A["_tag"]tag: function (type parameter) K in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
K,
f: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
f: (event: Extract<
A,
{
readonly _tag: K
}
>
event: type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) A in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
A, { readonly _tag: const K extends A["_tag"]_tag: function (type parameter) K in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
K }>) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, function (type parameter) E in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
E, function (type parameter) R in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, 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<void, function (type parameter) E in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
E, function (type parameter) R in <A extends TaggedEvent, const K extends A["_tag"], E, R>(self: Stream.Stream<A>, tag: K, f: (event: Extract<A, {
readonly _tag: K;
}>) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>
R>;
<function (type parameter) A in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>A extends type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent, function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases extends type TagHandlers<
A extends TaggedEvent,
E,
R
> = {
[P in keyof {
readonly [K in A["_tag"]]: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
}]?:
| {
readonly [K in A["_tag"]]: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
}[P]
| undefined
}
A partial set of per-_tag handlers over a tagged-event union — the handler-map form of
Hyperlink.runForEachTag
. Each handler receives the narrowed event for its tag.
TagHandlers<function (type parameter) A in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>A, unknown, unknown>>(
self: Stream.Stream<A, never, never>(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: import StreamStream.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 extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>A>,
handlers: Cases extends TagHandlers<A, unknown, unknown>handlers: function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases,
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, type HandlersError<Cases> = {
[K in keyof Cases]: Cases[K] extends (
event: never
) => Effect.Effect<unknown, infer E, unknown>
? E
: never
}[keyof Cases]
The union of every handler's error channel (extracted via infer, like Effect.catchTags).
HandlersError<function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases>, type HandlersContext<Cases> = {
[K in keyof Cases]: Cases[K] extends (
event: never
) => Effect.Effect<unknown, unknown, infer R>
? R
: never
}[keyof Cases]
The union of every handler's requirement channel — so R doesn't leak to unknown.
HandlersContext<function (type parameter) Cases in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<void, HandlersError<Cases>, HandlersContext<Cases>>Cases>>;
} = import FnFn.const dual: <(...args: Array<any>) => any, <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>) => Effect.Effect<void, E, R>>(isDataFirst: (args: IArguments) => boolean, body: <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>) => Effect.Effect<void, E, R>) => ((...args: Array<any>) => any) & (<E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>) => Effect.Effect<void, 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(
(args: IArgumentsargs) => import StreamStream.const isStream: (
u: unknown
) => u is Stream.Stream<unknown, unknown, unknown>
Checks whether a value is a Stream.
Example (Checking whether a value is a Stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.make(1, 2, 3)
const notStream = { data: [1, 2, 3] }
yield* Console.log(Stream.isStream(stream))
// true
yield* Console.log(Stream.isStream(notStream))
// false
})
Effect.runPromise(program)
isStream(args: IArgumentsargs[0]),
// Impl is typed over the concrete `TaggedEvent` base so `Match` (which needs a concrete
// union, not a generic) type-checks with no casts; the overload signatures above carry the
// precise per-tag types to callers.
<function (type parameter) E in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>E, function (type parameter) R in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>R>(
self: Stream.Stream<TaggedEvent, never, never>(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: import StreamStream.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<type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent>,
tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>tagOrHandlers: string | type TagHandlers<
A extends TaggedEvent,
E,
R
> = {
[P in keyof {
readonly [K in A["_tag"]]: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
}]?:
| {
readonly [K in A["_tag"]]: (
event: Extract<
A,
{
readonly _tag: K
}
>
) => Effect.Effect<void, E, R>
}[P]
| undefined
}
A partial set of per-_tag handlers over a tagged-event union — the handler-map form of
Hyperlink.runForEachTag
. Each handler receives the narrowed event for its tag.
TagHandlers<type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent, function (type parameter) E in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>E, function (type parameter) R in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>R>,
f: | ((
event: TaggedEvent
) => Effect.Effect<void, E, R>)
| undefined
f?: (event: TaggedEvent(parameter) event: {
_tag: string;
}
event: type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, function (type parameter) E in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>E, function (type parameter) R in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, 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<void, function (type parameter) E in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>E, function (type parameter) R in <E, R>(self: Stream.Stream<TaggedEvent>, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>, f?: (event: TaggedEvent) => Effect.Effect<void, E, R>): Effect.Effect<void, E, R>R> => {
const const matcher: (
input: TaggedEvent
) => Effect.Effect<void, E, R>
matcher =
typeof tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>tagOrHandlers === "string"
? import MatchMatch.const type: <
TaggedEvent
>() => Match.Matcher<
TaggedEvent,
Match.Types.Without<never>,
TaggedEvent,
never,
never,
any
>
Creates a matcher for a specific type.
When to use
Use to build a reusable matcher function for values of a known input type.
Details
This function defines a Matcher that operates on a given type, allowing you
to specify conditions for handling different cases. Once the matcher is
created, you can use pattern-matching functions like
when
to define
how different values should be processed.
Example (Matching Numbers and Strings)
import { Match } from "effect"
// Create a matcher for values that are either strings or numbers
//
// ┌─── (u: string | number) => string
// ▼
const match = Match.type<string | number>().pipe(
// Match when the value is a number
Match.when(Match.number, (n) => `number: ${n}`),
// Match when the value is a string
Match.when(Match.string, (s) => `string: ${s}`),
// Ensure all possible cases are handled
Match.exhaustive
)
console.log(match(0))
// Output: "number: 0"
console.log(match("hello"))
// Output: "string: hello"
type<type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent>().Pipeable.pipe<Match.Matcher<TaggedEvent, Match.Types.Without<never>, TaggedEvent, never, never, any>, Match.Matcher<TaggedEvent, Match.Types.Without<TaggedEvent>, never, Effect.Effect<void, E, R>, never, any>, (input: TaggedEvent) => Effect.Effect<void, E, R>>(this: Match.Matcher<...>, ab: (_: Match.Matcher<TaggedEvent, Match.Types.Without<never>, TaggedEvent, never, never, any>) => Match.Matcher<TaggedEvent, ... 4 more ..., any>, bc: (_: Match.Matcher<...>) => (input: TaggedEvent) => Effect.Effect<void, E, R>): (input: TaggedEvent) => Effect.Effect<void, E, R> (+21 overloads)pipe(
import MatchMatch.const tag: <TaggedEvent, string, any, (event: TaggedEvent) => Effect.Effect<void, E, R>>(...pattern: [first: string, ...values: string[], f: (event: TaggedEvent) => Effect.Effect<void, E, R>]) => <I, F, A, Pr>(self: Match.Matcher<I, F, TaggedEvent, A, Pr, any>) => Match.Matcher<I, Match.Types.AddWithout<F, TaggedEvent>, Match.Types.ApplyFilters<I, Match.Types.AddWithout<F, TaggedEvent>>, Effect.Effect<void, E, R> | A, Pr, any>Matches discriminated union members by their _tag field.
When to use
Use to handle one or more _tag cases with the same matcher branch.
Details
This helper follows the Effect convention that discriminated unions use
"_tag" as their discriminator field. Use
discriminator
for a
different discriminator field.
Example (Matching a discriminated union by tag)
import { Match } from "effect"
type Event =
| { readonly _tag: "fetch" }
| { readonly _tag: "success"; readonly data: string }
| { readonly _tag: "error"; readonly error: Error }
| { readonly _tag: "cancel" }
const match = Match.type<Event>().pipe(
// Match either "fetch" or "success"
Match.tag("fetch", "success", () => `Ok!`),
// Match "error" and extract the error message
Match.tag("error", (event) => `Error: ${event.error.message}`),
// Match "cancel"
Match.tag("cancel", () => "Cancelled"),
Match.exhaustive
)
console.log(match({ _tag: "success", data: "Hello" }))
// Output: "Ok!"
console.log(match({ _tag: "error", error: new Error("Oops!") }))
// Output: "Error: Oops!"
tag(tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>tagOrHandlers, f: | ((
event: TaggedEvent
) => Effect.Effect<void, E, R>)
| undefined
f ?? (() => import EffectEffect.const void: Effect.Effect<void, never, never>
export void
(alias) const void: {
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;
}
Returns an effect that succeeds with void.
void)),
import MatchMatch.const orElse: <never, any, () => Effect.Effect<void, never, never>>(f: () => Effect.Effect<void, never, never>) => <I, R, A, Pr>(self: Match.Matcher<I, R, never, A, Pr, any>) => [Pr] extends [never] ? (input: I) => Unify<Effect.Effect<void, never, never> | A> : Unify<Effect.Effect<void, never, never> | A>Provides a fallback value when no patterns match.
When to use
Use to finalize a matcher with a fallback for unmatched input.
Details
This function ensures that a matcher always returns a valid result, even if
no defined patterns match. It acts as a default case, similar to the
default clause in a switch statement or the final else in an if-else
chain.
Example (Providing a default value when no patterns match)
import { Match } from "effect"
// Create a matcher for string or number values
const match = Match.type<string | number>().pipe(
// Match when the value is "a"
Match.when("a", () => "ok"),
// Fallback when no patterns match
Match.orElse(() => "fallback")
)
console.log(match("a"))
// Output: "ok"
console.log(match("b"))
// Output: "fallback"
orElse(() => import EffectEffect.const void: Effect.Effect<void, never, never>
export void
(alias) const void: {
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;
}
Returns an effect that succeeds with void.
void),
)
: import MatchMatch.const type: <
TaggedEvent
>() => Match.Matcher<
TaggedEvent,
Match.Types.Without<never>,
TaggedEvent,
never,
never,
any
>
Creates a matcher for a specific type.
When to use
Use to build a reusable matcher function for values of a known input type.
Details
This function defines a Matcher that operates on a given type, allowing you
to specify conditions for handling different cases. Once the matcher is
created, you can use pattern-matching functions like
when
to define
how different values should be processed.
Example (Matching Numbers and Strings)
import { Match } from "effect"
// Create a matcher for values that are either strings or numbers
//
// ┌─── (u: string | number) => string
// ▼
const match = Match.type<string | number>().pipe(
// Match when the value is a number
Match.when(Match.number, (n) => `number: ${n}`),
// Match when the value is a string
Match.when(Match.string, (s) => `string: ${s}`),
// Ensure all possible cases are handled
Match.exhaustive
)
console.log(match(0))
// Output: "number: 0"
console.log(match("hello"))
// Output: "string: hello"
type<type TaggedEvent = {
readonly _tag: string
}
Anything with a string discriminant _tag — the element of an event stream.
TaggedEvent>().Pipeable.pipe<Match.Matcher<TaggedEvent, Match.Types.Without<never>, TaggedEvent, never, never, any>, Match.Matcher<TaggedEvent, Match.Types.Without<TaggedEvent>, never, Effect.Effect<void, E, R>, never, any>, (input: TaggedEvent) => Effect.Effect<void, E, R>>(this: Match.Matcher<...>, ab: (_: Match.Matcher<TaggedEvent, Match.Types.Without<never>, TaggedEvent, never, never, any>) => Match.Matcher<TaggedEvent, ... 4 more ..., any>, bc: (_: Match.Matcher<...>) => (input: TaggedEvent) => Effect.Effect<void, E, R>): (input: TaggedEvent) => Effect.Effect<void, E, R> (+21 overloads)pipe(
import MatchMatch.const tags: <TaggedEvent, any, Partial<{
readonly [x: string]: (event: TaggedEvent) => Effect.Effect<void, E, R>;
}>>(fields: Partial<{
readonly [x: string]: (event: TaggedEvent) => Effect.Effect<void, E, R>;
}>) => <I, F, A, Pr>(self: Match.Matcher<I, F, TaggedEvent, A, Pr, any>) => Match.Matcher<I, Match.Types.AddWithout<F, TaggedEvent>, Match.Types.ApplyFilters<I, Match.Types.AddWithout<F, TaggedEvent>>, Effect.Effect<...> | A, Pr, any>
Matches values based on their _tag field, mapping each tag to a
corresponding handler.
Details
This function provides a way to handle discriminated unions by mapping _tag
values to specific functions. Each handler receives the matched value and
returns a transformed result. If all possible tags are handled, you can
enforce exhaustiveness using Match.exhaustive to ensure no case is missed.
Example (Mapping tag handlers)
import { Match, pipe } from "effect"
const match = pipe(
Match.type<
{ _tag: "A"; a: string } | { _tag: "B"; b: number } | {
_tag: "C"
c: boolean
}
>(),
Match.tags({
A: (a) => a.a,
B: (b) => b.b,
C: (c) => c.c
}),
Match.exhaustive
)
tags(tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>tagOrHandlers),
import MatchMatch.const orElse: <never, any, () => Effect.Effect<void, never, never>>(f: () => Effect.Effect<void, never, never>) => <I, R, A, Pr>(self: Match.Matcher<I, R, never, A, Pr, any>) => [Pr] extends [never] ? (input: I) => Unify<Effect.Effect<void, never, never> | A> : Unify<Effect.Effect<void, never, never> | A>Provides a fallback value when no patterns match.
When to use
Use to finalize a matcher with a fallback for unmatched input.
Details
This function ensures that a matcher always returns a valid result, even if
no defined patterns match. It acts as a default case, similar to the
default clause in a switch statement or the final else in an if-else
chain.
Example (Providing a default value when no patterns match)
import { Match } from "effect"
// Create a matcher for string or number values
const match = Match.type<string | number>().pipe(
// Match when the value is "a"
Match.when("a", () => "ok"),
// Fallback when no patterns match
Match.orElse(() => "fallback")
)
console.log(match("a"))
// Output: "ok"
console.log(match("b"))
// Output: "fallback"
orElse(() => import EffectEffect.const void: Effect.Effect<void, never, never>
export void
(alias) const void: {
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;
}
Returns an effect that succeeds with void.
void),
);
return import StreamStream.const runForEach: <TaggedEvent, never, never, void, E, R>(self: Stream.Stream<TaggedEvent, never, never>, f: (a: TaggedEvent) => Effect.Effect<void, E, R>) => Effect.Effect<void, E, R> (+1 overload)Runs the provided effectful callback for each element of the stream.
Example (Running an effect for each value)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3)
const program = Effect.gen(function*() {
yield* Stream.runForEach(stream, (n) => Console.log(`Processing: ${n}`))
})
Effect.runPromise(program)
// Processing: 1
// Processing: 2
// Processing: 3
runForEach(self: Stream.Stream<TaggedEvent, never, never>(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, const matcher: (
input: TaggedEvent
) => Effect.Effect<void, E, R>
matcher);
},
);