<A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>Lifts failures and successes into a Result, yielding a stream that cannot fail.
Details
The stream ends after the first failure, emitting a Result.fail value.
Example (Converting failures to results)
import { Console, Effect, Result, Stream } from "effect"
const program = Effect.gen(function*() {
const results = yield* Stream.make(1, 2).pipe(
Stream.concat(Stream.fail("boom")),
Stream.result,
Stream.map(Result.match({
onFailure: (error) => `failure: ${error}`,
onSuccess: (value) => `success: ${value}`
})),
Stream.runCollect
)
yield* Console.log(results)
})
Effect.runPromise(program)
// Output: [ "success: 1", "success: 2", "failure: boom" ]export const const result: <A, E, R>(
self: Stream<A, E, R>
) => Stream<Result.Result<A, E>, never, R>
Lifts failures and successes into a Result, yielding a stream that cannot fail.
Details
The stream ends after the first failure, emitting a Result.fail value.
Example (Converting failures to results)
import { Console, Effect, Result, Stream } from "effect"
const program = Effect.gen(function*() {
const results = yield* Stream.make(1, 2).pipe(
Stream.concat(Stream.fail("boom")),
Stream.result,
Stream.map(Result.match({
onFailure: (error) => `failure: ${error}`,
onSuccess: (value) => `success: ${value}`
})),
Stream.runCollect
)
yield* Console.log(results)
})
Effect.runPromise(program)
// Output: [ "success: 1", "success: 2", "failure: boom" ]
result = <function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, 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>): Stream<Result.Result<A, E>, never, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>R>): 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<import ResultResult.type Result.Result = /*unresolved*/ anyResult<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, never, R>E>, never, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<Result.Result<A, E>, 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.pipe(
const map: {
<A, B>(f: (a: A, i: number) => B): <E, R>(
self: Stream<A, E, R>
) => Stream<B, E, R>
<A, E, R, B>(
self: Stream<A, E, R>,
f: (a: A, i: number) => B
): Stream<B, E, R>
}
map(import ResultResult.succeed),
const catch_: {
<E, A2, E2, R2>(
f: (error: E) => Stream<A2, E2, R2>
): <A, R>(
self: Stream<A, E, R>
) => Stream<A | A2, E2, R2 | R>
<A, E, R, A2, E2, R2>(
self: Stream<A, E, R>,
f: (error: E) => Stream<A2, E2, R2>
): Stream<A | A2, E2, R | R2>
}
catch_((e: unknowne) => const succeed: <A>(value: A) => Stream<A>Creates a single-valued pure stream.
Example (Creating a single-valued pure stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const values = yield* Stream.succeed(3).pipe(Stream.runCollect)
yield* Console.log(values)
})
Effect.runPromise(program)
// [ 3 ]
succeed(import ResultResult.fail(e: unknowne)))
)