<A>(options?: { readonly strategy?: QueuingStrategy<A> | undefined }): <
E
>(
self: Stream<A, E>
) => ReadableStream<A>
<A, E>(
self: Stream<A, E>,
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
): ReadableStream<A>Converts a stream to a ReadableStream.
Details
See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
Example (Converting a stream to a ReadableStream)
import { Stream } from "effect"
const readableStream = Stream.toReadableStream(Stream.make(1, 2, 3))
const reader = readableStream.getReader()export const const toReadableStream: {
<A>(options?: {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}): <E>(self: Stream<A, E>) => ReadableStream<A>
<A, E>(
self: Stream<A, E>,
options?: {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
): ReadableStream<A>
}
Converts a stream to a ReadableStream.
Details
See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
Example (Converting a stream to a ReadableStream)
import { Stream } from "effect"
const readableStream = Stream.toReadableStream(Stream.make(1, 2, 3))
const reader = readableStream.getReader()
toReadableStream: {
<function (type parameter) A in <A>(options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): <E>(self: Stream<A, E>) => ReadableStream<A>
A>(
options: | {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
| undefined
options?: { readonly strategy?: QueuingStrategy<A> | undefinedstrategy?: interface QueuingStrategy<T = any>QueuingStrategy<function (type parameter) A in <A>(options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): <E>(self: Stream<A, E>) => ReadableStream<A>
A> | undefined }
): <function (type parameter) E in <E>(self: Stream<A, E>): ReadableStream<A>E>(
self: Stream<A, E>(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>(options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): <E>(self: Stream<A, E>) => ReadableStream<A>
A, function (type parameter) E in <E>(self: Stream<A, E>): ReadableStream<A>E>
) => interface ReadableStream<R = any>The ReadableStream interface of the Streams API represents a readable stream of byte data.
ReadableStream<function (type parameter) A in <A>(options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): <E>(self: Stream<A, E>) => ReadableStream<A>
A>
<function (type parameter) A in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A, function (type parameter) E in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
E>(
self: Stream<A, E>(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>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A, function (type parameter) E in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
E>,
options: | {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
| undefined
options?: { readonly strategy?: QueuingStrategy<A> | undefinedstrategy?: interface QueuingStrategy<T = any>QueuingStrategy<function (type parameter) A in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A> | undefined }
): interface ReadableStream<R = any>The ReadableStream interface of the Streams API represents a readable stream of byte data.
ReadableStream<function (type parameter) A in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A>
} = dual<(...args: Array<any>) => any, <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}) => ReadableStream<A>>(isDataFirst: (args: IArguments) => boolean, body: <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}) => ReadableStream<A>): ((...args: Array<any>) => any) & (<A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}) => ReadableStream<A>) (+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>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A, function (type parameter) E in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
E>(
self: Stream<A, E>(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>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A, function (type parameter) E in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
E>,
options: | {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
| undefined
options?: { readonly strategy?: QueuingStrategy<A> | undefinedstrategy?: interface QueuingStrategy<T = any>QueuingStrategy<function (type parameter) A in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A> | undefined }
): interface ReadableStream<R = any>The ReadableStream interface of the Streams API represents a readable stream of byte data.
ReadableStream<function (type parameter) A in <A, E>(self: Stream<A, E>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): ReadableStream<A>
A> => const toReadableStreamWith: (<A, XR>(
context: Context.Context<XR>,
options?: {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
) => <E, R extends XR>(
self: Stream<A, E, R>
) => ReadableStream<A>) &
(<A, E, XR, R extends XR>(
self: Stream<A, E, R>,
context: Context.Context<XR>,
options?: {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
) => ReadableStream<A>)
toReadableStreamWith(self: Stream<A, E>(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 ContextContext.const empty: () => Context<never>Returns an empty Context.
Example (Creating an empty context)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isContext(Context.empty()), true)
empty(), options: | {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
| undefined
options)
)