<OutElem, OutErr, OutDone, Env>(
self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>,
scope: Scope.Scope
): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>Converts a channel to a Pull within an existing scope.
Example (Converting channels to scoped pulls)
import { Channel, Data, Effect, Scope } from "effect"
class ScopedPullError extends Data.TaggedError("ScopedPullError")<{
readonly reason: string
}> {}
// Create a channel
const numbersChannel = Channel.fromIterable([1, 2, 3])
// Convert to Pull with explicit scope
const scopedPullEffect = Effect.gen(function*() {
const scope = yield* Scope.make()
const pull = yield* Channel.toPullScoped(numbersChannel, scope)
return pull
})export const const toPullScoped: <
OutElem,
OutErr,
OutDone,
Env
>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>,
scope: Scope.Scope
) => Effect.Effect<
Pull.Pull<OutElem, OutErr, OutDone, Env>,
never,
Env
>
Converts a channel to a Pull within an existing scope.
Example (Converting channels to scoped pulls)
import { Channel, Data, Effect, Scope } from "effect"
class ScopedPullError extends Data.TaggedError("ScopedPullError")<{
readonly reason: string
}> {}
// Create a channel
const numbersChannel = Channel.fromIterable([1, 2, 3])
// Convert to Pull with explicit scope
const scopedPullEffect = Effect.gen(function*() {
const scope = yield* Scope.make()
const pull = yield* Channel.toPullScoped(numbersChannel, scope)
return pull
})
toPullScoped = <function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutDone, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>Env>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
(parameter) self: {
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 Channel<out OutElem, out OutErr = never, out OutDone = void, in InElem = unknown, in InErr = unknown, in InDone = unknown, out Env = never>A Channel is a nexus of I/O operations, which supports both reading and
writing. A channel may read values of type InElem and write values of type
OutElem. When the channel finishes, it yields a value of type OutDone. A
channel may fail with a value of type OutErr.
Details
Channels are the foundation of Streams: both streams and sinks are built on
channels. Most users shouldn't have to use channels directly, as streams and
sinks are much more convenient and cover all common use cases. However, when
adding new stream and sink operators, or doing something highly specialized,
it may be useful to use channels directly.
Channels compose in a variety of ways:
- Piping: One channel can be piped to another channel, assuming the
input type of the second is the same as the output type of the first.
- Sequencing: The terminal value of one channel can be used to create
another channel, and both the first channel and the function that makes
the second channel can be composed into a channel.
- Concatenating: The output of one channel can be used to create other
channels, which are all concatenated together. The first channel and the
function that makes the other channels can be composed into a channel.
Example (Typing channels)
import type { Channel } from "effect"
// A channel that outputs numbers and requires no environment
type NumberChannel = Channel.Channel<number>
// A channel that outputs strings, can fail with Error, completes with boolean
type StringChannel = Channel.Channel<string, Error, boolean>
// A channel with all type parameters specified
type FullChannel = Channel.Channel<
string, // OutElem - output elements
Error, // OutErr - output errors
number, // OutDone - completion value
number, // InElem - input elements
string, // InErr - input errors
boolean, // InDone - input completion
{ db: string } // Env - required environment
>
Channel<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutDone, unknown, unknown, unknown, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>Env>,
scope: Scope.Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: import ScopeScope.Scope
): 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<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>OutDone, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>Env>, never, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>, scope: Scope.Scope): Effect.Effect<Pull.Pull<OutElem, OutErr, OutDone, Env>, never, Env>Env> => const toTransform: <
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>(
channel: Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>
) => (
upstream: Pull.Pull<InElem, InErr, InDone>,
scope: Scope.Scope
) => Effect.Effect<
Pull.Pull<OutElem, OutErr, OutDone>,
never,
Env
>
Converts a Channel back to its underlying transformation function.
Example (Extracting channel transforms)
import { Channel } from "effect"
const channel = Channel.succeed(42)
const transform = Channel.toTransform(channel)
// transform can now be used directly
toTransform(self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
(parameter) self: {
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 CauseCause.done(), scope: Scope.Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope)