<A, E, R>(self: Stream<A, E, R>): Effect.Effect<
Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>,
never,
R | Scope.Scope
>Returns a scoped pull for manually consuming the stream's output chunks.
Details
The pull fails with Cause.Done when the stream ends and with the stream
error on failure.
Example (Creating a scoped pull)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3)
const program = Effect.scoped(
Effect.gen(function*() {
const pull = yield* Stream.toPull(stream)
const chunk = yield* pull
yield* Console.log(chunk)
})
)
Effect.runPromise(program)
// [1, 2, 3]export const const toPull: <A, E, R>(
self: Stream<A, E, R>
) => Effect.Effect<
Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>,
never,
R | Scope.Scope
>
Returns a scoped pull for manually consuming the stream's output chunks.
Details
The pull fails with Cause.Done when the stream ends and with the stream
error on failure.
Example (Creating a scoped pull)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3)
const program = Effect.scoped(
Effect.gen(function*() {
const pull = yield* Stream.toPull(stream)
const chunk = yield* pull
yield* Console.log(chunk)
})
)
Effect.runPromise(program)
// [1, 2, 3]
toPull = <function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | 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, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, 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 PullPull.interface Pull<out A, out E = never, out Done = void, out R = never>An effectful pull step that either produces a value, fails with E, or
signals completion with Cause.Done<Done>.
When to use
Use to model one low-level pull step when a consumer repeatedly evaluates an
effect that may emit a value, fail normally, or signal normal completion
through Cause.Done.
Details
Pull represents completion in the error channel so low-level stream
consumers can distinguish ordinary failures from end-of-input and carry a
leftover value when needed.
Pull<import ArrArr.type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>A>, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>E>, never, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E>, never, R | Scope.Scope>R | import ScopeScope.Scope> => import ChannelChannel.const toPull: <
OutElem,
OutErr,
OutDone,
Env
>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
) => Effect.Effect<
Pull.Pull<OutElem, OutErr, OutDone>,
never,
Env | Scope.Scope
>
Converts a channel to a scoped Pull for low-level consumption.
Details
The effect requires a Scope. The returned pull should be consumed only
while that scope remains open. Pulls are serialized so only one pull is
evaluated at a time.
Example (Converting channels to pulls)
import { Channel, Data, Effect } from "effect"
class PullError extends Data.TaggedError("PullError")<{
readonly step: string
}> {}
// Create a channel
const numbersChannel = Channel.fromIterable([1, 2, 3])
// Convert to Pull within a scope
const pullEffect = Effect.scoped(
Channel.toPull(numbersChannel)
)
// Use the Pull to manually consume elements
toPull(self: Stream<A, E, R>(parameter) self: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.Stream<A, E, R>.channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>(property) Stream<A, E, R>.channel: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
channel)