<A>(options?: { readonly strategy?: QueuingStrategy<A> | undefined }): <
E,
R
>(
self: Stream<A, E, R>
) => Effect.Effect<ReadableStream<A>, never, R>
<A, E, R>(
self: Stream<A, E, R>,
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
): Effect.Effect<ReadableStream<A>, never, R>Creates an Effect that builds a ReadableStream from the stream.
When to use
Use when bridging to Web Streams from inside an Effect so the required
services can be captured from the current context.
Details
See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
Example (Creating a ReadableStream effect)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3, 4, 5)
const effect = Effect.gen(function*() {
const readableStream = yield* Stream.toReadableStreamEffect(stream)
yield* Console.log(readableStream instanceof ReadableStream) // true
})
Effect.runPromise(effect)export const const toReadableStreamEffect: {
<A>(options?: {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}): <E, R>(
self: Stream<A, E, R>
) => Effect.Effect<ReadableStream<A>, never, R>
<A, E, R>(
self: Stream<A, E, R>,
options?: {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
): Effect.Effect<ReadableStream<A>, never, R>
}
Creates an Effect that builds a ReadableStream from the stream.
When to use
Use when bridging to Web Streams from inside an Effect so the required
services can be captured from the current context.
Details
See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
Example (Creating a ReadableStream effect)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3, 4, 5)
const effect = Effect.gen(function*() {
const readableStream = yield* Stream.toReadableStreamEffect(stream)
yield* Console.log(readableStream instanceof ReadableStream) // true
})
Effect.runPromise(effect)
toReadableStreamEffect: {
<function (type parameter) A in <A>(options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<ReadableStream<A>, never, R>
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, R>(self: Stream<A, E, R>) => Effect.Effect<ReadableStream<A>, never, R>
A> | undefined }
): <function (type parameter) E in <E, R>(self: Stream<A, E, R>): Effect.Effect<ReadableStream<A>, never, R>E, function (type parameter) R in <E, R>(self: Stream<A, E, R>): Effect.Effect<ReadableStream<A>, never, R>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>(options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): <E, R>(self: Stream<A, E, R>) => Effect.Effect<ReadableStream<A>, never, R>
A, function (type parameter) E in <E, R>(self: Stream<A, E, R>): Effect.Effect<ReadableStream<A>, never, R>E, function (type parameter) R in <E, R>(self: Stream<A, E, R>): Effect.Effect<ReadableStream<A>, never, R>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<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, R>(self: Stream<A, E, R>) => Effect.Effect<ReadableStream<A>, never, R>
A>, never, function (type parameter) R in <E, R>(self: Stream<A, E, R>): Effect.Effect<ReadableStream<A>, never, R>R>
<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
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>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
R>,
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, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A> | 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<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, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A>, never, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
R>
} = dual<(...args: Array<any>) => any, <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}) => Effect.Effect<ReadableStream<A>, never, R>>(isDataFirst: (args: IArguments) => boolean, body: <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}) => Effect.Effect<ReadableStream<A>, never, R>): ((...args: Array<any>) => any) & (<A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}) => Effect.Effect<ReadableStream<A>, never, R>) (+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>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
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>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
R>,
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, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A> | 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<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, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
A>, never, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
R> =>
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(
import EffectEffect.const context: <R = never>() => Effect<
Context.Context<R>,
never,
R
>
Returns the complete context.
When to use
Use to read the complete Context available to the current effect.
Details
This function allows you to access all services that are currently available
in the effect's environment. This can be useful for debugging, introspection,
or when you need to pass the entire context to another function.
Example (Reading the full context)
import { Console, Context, Effect, Option } from "effect"
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
const program = Effect.gen(function*() {
const allServices = yield* Effect.context()
// Check if specific services are available
const loggerOption = Context.getOption(allServices, Logger)
const databaseOption = Context.getOption(allServices, Database)
yield* Console.log(`Logger available: ${Option.isSome(loggerOption)}`)
yield* Console.log(`Database available: ${Option.isSome(databaseOption)}`)
})
const context = Context.make(Logger, { log: console.log })
.pipe(Context.add(Database, { query: () => "result" }))
const provided = Effect.provideContext(program, context)
context<function (type parameter) R in <A, E, R>(self: Stream<A, E, R>, options?: {
readonly strategy?: QueuingStrategy<A> | undefined;
}): Effect.Effect<ReadableStream<A>, never, R>
R>(),
(context: Context.Context<R>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
context) => 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, 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, context: Context.Context<R>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
context, options: | {
readonly strategy?:
| QueuingStrategy<A>
| undefined
}
| undefined
options)
)
)