<A, Pass, Fail, EX, RX>(
filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>,
options?: {
readonly capacity?: number | "unbounded" | undefined
readonly concurrency?: number | "unbounded" | undefined
}
): <E, R>(
self: Stream<A, E, R>
) => Effect.Effect<
[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>],
never,
R | RX | Scope.Scope
>
<A, E, R, Pass, Fail, EX, RX>(
self: Stream<A, E, R>,
filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>,
options?: {
readonly capacity?: number | "unbounded" | undefined
readonly concurrency?: number | "unbounded" | undefined
}
): Effect.Effect<
[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>],
never,
R | RX | Scope.Scope
>Splits a stream with an effectful Filter, returning scoped streams for
filter successes and failures.
When to use
Use when you need to classify each stream element with an effectful Filter
and consume both passing and failing mapped values as streams.
Details
The returned streams are backed by queues in the current scope and should be consumed while that scope remains open. The first stream emits success values from the filter, and the second emits failure values.
export const const partitionEffect: {
<A, Pass, Fail, EX, RX>(
filter: Filter.FilterEffect<
NoInfer<A>,
Pass,
Fail,
EX,
RX
>,
options?: {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
): <E, R>(
self: Stream<A, E, R>
) => Effect.Effect<
[
passes: Stream<Pass, E | EX>,
fails: Stream<Fail, E | EX>
],
never,
R | RX | Scope.Scope
>
<A, E, R, Pass, Fail, EX, RX>(
self: Stream<A, E, R>,
filter: Filter.FilterEffect<
NoInfer<A>,
Pass,
Fail,
EX,
RX
>,
options?: {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
): Effect.Effect<
[
passes: Stream<Pass, E | EX>,
fails: Stream<Fail, E | EX>
],
never,
R | RX | Scope.Scope
>
}
Splits a stream with an effectful Filter, returning scoped streams for
filter successes and failures.
When to use
Use when you need to classify each stream element with an effectful Filter
and consume both passing and failing mapped values as streams.
Details
The returned streams are backed by queues in the current scope and should be
consumed while that scope remains open. The first stream emits success values
from the filter, and the second emits failure values.
partitionEffect: {
<function (type parameter) A in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A, function (type parameter) Pass in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) EX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) RX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX>(filter: Filter.FilterEffect<
NoInfer<A>,
Pass,
Fail,
EX,
RX
>
filter: import FilterFilter.interface FilterEffect<in Input, out Pass, out Fail, out E = never, out R = never>Represents an effectful filter function that can produce Effects.
Details
Similar to a regular Filter, but the filtering operation itself can be
effectful, allowing for asynchronous operations, error handling, and
dependency injection.
Example (Defining an effectful user filter)
import { Effect, Filter, Result } from "effect"
// An effectful filter that validates user data
type User = { id: string; isActive: boolean }
type ValidationError = { message: string }
const validateUser: Filter.FilterEffect<
string,
User,
User,
ValidationError,
never
> = (id) =>
Effect.gen(function*() {
const user: User = { id, isActive: id.length > 0 }
return user.isActive ? Result.succeed(user) : Result.fail(user)
})
FilterEffect<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A>, function (type parameter) Pass in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) EX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) RX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX>, options: | {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
| undefined
options?: {
readonly capacity?: number | "unbounded" | undefinedcapacity?: number | "unbounded" | undefined
readonly concurrency?: number | "unbounded" | undefinedconcurrency?: number | "unbounded" | undefined
}): <function (type parameter) E in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>E, function (type parameter) R in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>R>(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A, function (type parameter) E in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>E, function (type parameter) R in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | 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<
[
Stream<Pass, EX | E, 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
passes: 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) Pass in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) E in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>E | function (type parameter) EX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX>,
Stream<Fail, EX | E, 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
fails: 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) Fail in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) E in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>E | function (type parameter) EX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX>
],
never,
function (type parameter) R in <E, R>(self: Stream<A, E, R>): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>R | function (type parameter) RX in <A, Pass, Fail, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX | import ScopeScope.Scope
>
<function (type parameter) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E, function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R, function (type parameter) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX>(
self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E, function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R>,
filter: Filter.FilterEffect<
NoInfer<A>,
Pass,
Fail,
EX,
RX
>
filter: import FilterFilter.interface FilterEffect<in Input, out Pass, out Fail, out E = never, out R = never>Represents an effectful filter function that can produce Effects.
Details
Similar to a regular Filter, but the filtering operation itself can be
effectful, allowing for asynchronous operations, error handling, and
dependency injection.
Example (Defining an effectful user filter)
import { Effect, Filter, Result } from "effect"
// An effectful filter that validates user data
type User = { id: string; isActive: boolean }
type ValidationError = { message: string }
const validateUser: Filter.FilterEffect<
string,
User,
User,
ValidationError,
never
> = (id) =>
Effect.gen(function*() {
const user: User = { id, isActive: id.length > 0 }
return user.isActive ? Result.succeed(user) : Result.fail(user)
})
FilterEffect<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A>, function (type parameter) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX>,
options: | {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
| undefined
options?: {
readonly capacity?: number | "unbounded" | undefinedcapacity?: number | "unbounded" | undefined
readonly concurrency?: number | "unbounded" | undefinedconcurrency?: number | "unbounded" | undefined
}
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
[
Stream<Pass, E | EX, 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
passes: 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) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E | function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX>,
Stream<Fail, E | EX, 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
fails: 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) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E | function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX>
],
never,
function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R | function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX | import ScopeScope.Scope
>
} = dual<(...args: Array<any>) => any, <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>>(isDataFirst: (args: IArguments) => boolean, body: <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>): ((...args: Array<any>) => any) & (<A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}) => Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | 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) => const isStream: (
u: unknown
) => u is 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) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E, function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R, function (type parameter) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX>(
self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E, function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R>,
filter: Filter.FilterEffect<
NoInfer<A>,
Pass,
Fail,
EX,
RX
>
filter: import FilterFilter.interface FilterEffect<in Input, out Pass, out Fail, out E = never, out R = never>Represents an effectful filter function that can produce Effects.
Details
Similar to a regular Filter, but the filtering operation itself can be
effectful, allowing for asynchronous operations, error handling, and
dependency injection.
Example (Defining an effectful user filter)
import { Effect, Filter, Result } from "effect"
// An effectful filter that validates user data
type User = { id: string; isActive: boolean }
type ValidationError = { message: string }
const validateUser: Filter.FilterEffect<
string,
User,
User,
ValidationError,
never
> = (id) =>
Effect.gen(function*() {
const user: User = { id, isActive: id.length > 0 }
return user.isActive ? Result.succeed(user) : Result.fail(user)
})
FilterEffect<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A>, function (type parameter) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX>,
options: | {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
| undefined
options?: {
readonly capacity?: number | "unbounded" | undefinedcapacity?: number | "unbounded" | undefined
readonly concurrency?: number | "unbounded" | undefinedconcurrency?: number | "unbounded" | undefined
}
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
[
Stream<Pass, E | EX, 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
passes: 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) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E | function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX>,
Stream<Fail, E | EX, 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
fails: 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) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E | function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX>
],
never,
function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R | function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX | import ScopeScope.Scope
> =>
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(
const partitionQueue: {
<A, Pass, Fail>(
filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
options?: {
readonly capacity?:
| number
| "unbounded"
| undefined
}
): <E, R>(
self: Stream<A, E, R>
) => Effect.Effect<
[
passes: Queue.Dequeue<Pass, E | Cause.Done>,
fails: Queue.Dequeue<Fail, E | Cause.Done>
],
never,
R | Scope.Scope
>
<A, E, R, Pass, Fail>(
self: Stream<A, E, R>,
filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
options?: {
readonly capacity?:
| number
| "unbounded"
| undefined
}
): Effect.Effect<
[
passes: Queue.Dequeue<Pass, E | Cause.Done>,
fails: Queue.Dequeue<Fail, E | Cause.Done>
],
never,
R | Scope.Scope
>
}
partitionQueue<import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail>, function (type parameter) E in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
E | function (type parameter) EX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
EX, function (type parameter) R in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
R | function (type parameter) RX in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
RX, function (type parameter) Pass in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Pass, function (type parameter) Fail in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
Fail>(
const mapEffect: {
<A, A2, E2, R2>(
f: (
a: A,
i: number
) => Effect.Effect<A2, E2, R2>,
options?:
| {
readonly concurrency?:
| number
| "unbounded"
| undefined
readonly unordered?: boolean | undefined
}
| undefined
): <E, R>(
self: Stream<A, E, R>
) => Stream<A2, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Stream<A, E, R>,
f: (
a: A,
i: number
) => Effect.Effect<A2, E2, R2>,
options?:
| {
readonly concurrency?:
| number
| "unbounded"
| undefined
readonly unordered?: boolean | undefined
}
| undefined
): Stream<A2, E | E2, R | R2>
}
mapEffect(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self, (a: Aa) => filter: Filter.FilterEffect<
NoInfer<A>,
Pass,
Fail,
EX,
RX
>
filter(a: Aa as type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, E, R, Pass, Fail, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>, options?: {
readonly capacity?: number | "unbounded" | undefined;
readonly concurrency?: number | "unbounded" | undefined;
}): Effect.Effect<[passes: Stream<Pass, E | EX>, fails: Stream<Fail, E | EX>], never, R | RX | Scope.Scope>
A>), options: | {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
| undefined
options),
(result: Result.Result<Pass, Fail>result) => result: Result.Result<Pass, Fail>result,
options: | {
readonly capacity?:
| number
| "unbounded"
| undefined
readonly concurrency?:
| number
| "unbounded"
| undefined
}
| undefined
options
),
([passes: Queue.Dequeue<
Pass,
Cause.Done<void> | E | EX
>
(parameter) passes: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
passes, fails: Queue.Dequeue<
Fail,
Cause.Done<void> | E | EX
>
(parameter) fails: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
fails]) => [const fromQueue: <A, E>(
queue: Queue.Dequeue<A, E>
) => Stream<A, Exclude<E, Cause.Done>>
Creates a stream that pulls values from a Queue.Dequeue.
Details
The stream emits non-empty batches of queued values and ends when the queue
fails with Cause.Done; other queue failures are propagated.
Example (Creating a stream from a queue of values)
import { Console, Effect, Queue, Stream } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.unbounded<number>()
yield* Queue.offer(queue, 1)
yield* Queue.offer(queue, 2)
yield* Queue.offer(queue, 3)
yield* Queue.shutdown(queue)
const stream = Stream.fromQueue(queue)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
fromQueue(passes: Queue.Dequeue<
Pass,
Cause.Done<void> | E | EX
>
(parameter) passes: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
passes), const fromQueue: <A, E>(
queue: Queue.Dequeue<A, E>
) => Stream<A, Exclude<E, Cause.Done>>
Creates a stream that pulls values from a Queue.Dequeue.
Details
The stream emits non-empty batches of queued values and ends when the queue
fails with Cause.Done; other queue failures are propagated.
Example (Creating a stream from a queue of values)
import { Console, Effect, Queue, Stream } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.unbounded<number>()
yield* Queue.offer(queue, 1)
yield* Queue.offer(queue, 2)
yield* Queue.offer(queue, 3)
yield* Queue.shutdown(queue)
const stream = Stream.fromQueue(queue)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
fromQueue(fails: Queue.Dequeue<
Fail,
Cause.Done<void> | E | EX
>
(parameter) fails: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
fails)] as type const = [Stream<Pass, Exclude<E, Cause.Done<void>> | Exclude<EX, Cause.Done<void>>, never>, Stream<Fail, Exclude<E, Cause.Done<void>> | Exclude<EX, Cause.Done<void>>, never>]const
)
)