<A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(
handlers: Cases
): (
self: Stream.Stream<A>
) => Effect.Effect<
Fiber.Fiber<void, HandlersError<Cases>>,
never,
HandlersContext<Cases> | Scope.Scope
>
<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
<A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(
self: Stream.Stream<A>,
handlers: Cases
): Effect.Effect<
Fiber.Fiber<void, HandlersError<Cases>>,
never,
HandlersContext<Cases> | Scope.Scope
>Like runForEachTag, but non-blocking: it forks the consumer into the enclosing
Scope (Effect.forkScoped) and hands back the Fiber, instead of running
the stream to completion. This is the common case for live observation — start watching the
events/status/metrics of a queue (or any tagged stream) in the background while the rest
of your program runs; the fiber is interrupted automatically when the scope closes (the
Effect.scoped block ends, or the owning layer is torn down), so you never track or kill it.
Each handler's error surfaces in the fiber's failure channel (not the caller's). If you
instead want to block until a (finite) stream drains — e.g. in a test — use
runForEachTag and yield* it directly, or Fiber.join the fiber this returns.
// no manual `Effect.forkScoped` — observation runs in the background, bound to the scope
yield* queue.events.pipe(Hyperlink.runForEachTagScoped({
Completed: ({ entry }) => Effect.log(`done ${entry.entryId}`),
Failed: ({ cause }) => Effect.logError("job failed", cause),
}))export const const runForEachTagScoped: {
<
A extends TaggedEvent,
Cases extends TagHandlers<A, unknown, unknown>
>(
handlers: Cases
): (
self: Stream.Stream<A>
) => Effect.Effect<
Fiber.Fiber<void, HandlersError<Cases>>,
never,
HandlersContext<Cases> | Scope.Scope
>
<
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<
Fiber.Fiber<void, E>,
never,
R | Scope.Scope
>
<
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<
Fiber.Fiber<void, E>,
never,
R | Scope.Scope
>
<
A extends TaggedEvent,
Cases extends TagHandlers<A, unknown, unknown>
>(
self: Stream.Stream<A>,
handlers: Cases
): Effect.Effect<
Fiber.Fiber<void, HandlersError<Cases>>,
never,
HandlersContext<Cases> | Scope.Scope
>
}
Like
runForEachTag
, but non-blocking: it forks the consumer into the enclosing
Scope
(
Effect.forkScoped
) and hands back the
Fiber
, instead of running
the stream to completion. This is the common case for live observation — start watching the
events/status/metrics of a queue (or any tagged stream) in the background while the rest
of your program runs; the fiber is interrupted automatically when the scope closes (the
Effect.scoped block ends, or the owning layer is torn down), so you never track or kill it.
Each handler's error surfaces in the fiber's failure channel (not the caller's). If you
instead want to block until a (finite) stream drains — e.g. in a test — use
runForEachTag
and yield* it directly, or Fiber.join the fiber this returns.
// no manual `Effect.forkScoped` — observation runs in the background, bound to the scope
yield* queue.events.pipe(Hyperlink.runForEachTagScoped({
Completed: ({ entry }) => Effect.log(`done ${entry.entryId}`),
Failed: ({ cause }) => Effect.logError("job failed", cause),
}))
runForEachTagScoped: {
// ── data-last (pipeable) ──
<function (type parameter) A in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(handlers: Cases): (self: Stream.Stream<A>) => Effect.Effect<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>A>,
) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>Cases>>,
never,
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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>Cases> | import ScopeScope.Scope
>;
<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
A>,
) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
E>, never, 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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
R | import ScopeScope.Scope>;
// ── 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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
R>,
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
E>, never, 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<Fiber.Fiber<void, E>, never, R | Scope.Scope>
R | import ScopeScope.Scope>;
<function (type parameter) A in <A extends TaggedEvent, Cases extends TagHandlers<A, unknown, unknown>>(self: Stream.Stream<A>, handlers: Cases): Effect.Effect<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>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<
import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>Cases>>,
never,
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<Fiber.Fiber<void, HandlersError<Cases>>, never, HandlersContext<Cases> | Scope.Scope>Cases> | import ScopeScope.Scope
>;
} = 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<Fiber.Fiber<void, E>, never, R | Scope.Scope>>(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<Fiber.Fiber<void, E>, never, R | Scope.Scope>) => ((...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<Fiber.Fiber<void, E>, never, R | Scope.Scope>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
(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]),
<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>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<Fiber.Fiber<void, E>, never, R | Scope.Scope>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<Fiber.Fiber<void, E>, never, R | Scope.Scope>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<Fiber.Fiber<void, E>, never, R | Scope.Scope>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<Fiber.Fiber<void, E>, never, R | Scope.Scope>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<Fiber.Fiber<void, E>, never, R | Scope.Scope>R>,
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<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<Fiber.Fiber<void, E>, never, R | Scope.Scope>E>, never, 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<Fiber.Fiber<void, E>, never, R | Scope.Scope>R | import ScopeScope.Scope> =>
// Delegate to the blocking consumer, then fork it into the enclosing scope. The two-arg
// (single-tag) and one-arg (handler-map) shapes are dispatched by `runForEachTag` itself.
import EffectEffect.const forkScoped: <Effect.Effect<void, E, R>>(effectOrOptions?: Effect.Effect<void, E, R> | undefined, options?: {
readonly startImmediately?: boolean | undefined;
readonly uninterruptible?: boolean | "inherit" | undefined;
} | undefined) => Effect.Effect<Fiber.Fiber<void, E>, never, Scope.Scope | R>
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(
f: | ((
event: TaggedEvent
) => Effect.Effect<void, E, R>)
| undefined
f === var undefinedundefined
? 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>
>
}
runForEachTag(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, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>tagOrHandlers as 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<Fiber.Fiber<void, E>, never, R | Scope.Scope>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<Fiber.Fiber<void, E>, never, R | Scope.Scope>R>)
: 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>
>
}
runForEachTag(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, tagOrHandlers: string | TagHandlers<TaggedEvent, E, R>tagOrHandlers as string, f: (
event: TaggedEvent
) => Effect.Effect<void, E, R>
f),
),
);