<A, D, E>(
iterable: AsyncIterable<A, D>,
onError: (error: unknown) => E
): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>Creates a channel from an AsyncIterable, emitting each yielded value as a
single-element non-empty array.
Details
The iterator's return value becomes the channel's done value. Thrown or
rejected iterator errors are converted with onError. If the channel scope
closes early and the iterator has a return method, that method is called.
export const const fromAsyncIterableArray: <A, D, E>(
iterable: AsyncIterable<A, D>,
onError: (error: unknown) => E
) => Channel<Arr.NonEmptyReadonlyArray<A>, E, D>
Creates a channel from an AsyncIterable, emitting each yielded value as a
single-element non-empty array.
Details
The iterator's return value becomes the channel's done value. Thrown or
rejected iterator errors are converted with onError. If the channel scope
closes early and the iterator has a return method, that method is called.
fromAsyncIterableArray = <function (type parameter) A in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>A, function (type parameter) D in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>D, function (type parameter) E in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>E>(
iterable: AsyncIterable<A, D>iterable: interface AsyncIterable<T, TReturn = any, TNext = any>AsyncIterable<function (type parameter) A in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>A, function (type parameter) D in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>D>,
onError: (error: unknown) => EonError: (error: unknownerror: unknown) => function (type parameter) E in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>E
): 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<import ArrArr.type Arr.NonEmptyReadonlyArray = /*unresolved*/ anyNonEmptyReadonlyArray<function (type parameter) A in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>A>, function (type parameter) E in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>E, function (type parameter) D in <A, D, E>(iterable: AsyncIterable<A, D>, onError: (error: unknown) => E): Channel<Arr.NonEmptyReadonlyArray<A>, E, D>D> => const map: {
<OutElem, OutElem2>(
f: (o: OutElem, i: number) => OutElem2
): <
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>(
self: Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>
) => Channel<
OutElem2,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>
<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env,
OutElem2
>(
self: Channel<
OutElem,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>,
f: (o: OutElem, i: number) => OutElem2
): Channel<
OutElem2,
OutErr,
OutDone,
InElem,
InErr,
InDone,
Env
>
}
map(const fromAsyncIterable: <A, D, E>(
iterable: AsyncIterable<A, D>,
onError: (error: unknown) => E
) => Channel<A, E, D>
Creates a channel that pulls values from an AsyncIterable.
Details
Each yielded value is emitted as an output element. The iterator's return
value becomes the channel's done value. Thrown or rejected iterator errors
are converted with onError. If the channel scope closes early and the
iterator has a return method, that method is called.
fromAsyncIterable(iterable: AsyncIterable<A, D>iterable, onError: (error: unknown) => EonError), import ArrArr.of)