<E>(evaluate: LazyArg<E>): Stream<never, E>Terminates with the specified lazily evaluated error.
Example (Failing a stream lazily)
import { Console, Effect, Stream } from "effect"
const stream = Stream.failSync(() => "Uh oh!")
const program = Effect.gen(function*() {
const exit = yield* Stream.runCollect(stream).pipe(Effect.exit)
yield* Console.log(exit)
})
Effect.runPromise(program)
// Output:
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }constructors
Source effect/Stream.ts:9511 lines
export const const failSync: <E>(
evaluate: LazyArg<E>
) => Stream<never, E>
Terminates with the specified lazily evaluated error.
Example (Failing a stream lazily)
import { Console, Effect, Stream } from "effect"
const stream = Stream.failSync(() => "Uh oh!")
const program = Effect.gen(function*() {
const exit = yield* Stream.runCollect(stream).pipe(Effect.exit)
yield* Console.log(exit)
})
Effect.runPromise(program)
// Output:
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
failSync = <function (type parameter) E in <E>(evaluate: LazyArg<E>): Stream<never, E>E>(evaluate: LazyArg<E>evaluate: import LazyArgLazyArg<function (type parameter) E in <E>(evaluate: LazyArg<E>): Stream<never, E>E>): 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<never, function (type parameter) E in <E>(evaluate: LazyArg<E>): Stream<never, E>E> => const fromChannel: <
Arr extends Arr.NonEmptyReadonlyArray<any>,
E,
R
>(
channel: Channel.Channel<
Arr,
E,
void,
unknown,
unknown,
unknown,
R
>
) => Stream<
Arr extends Arr.NonEmptyReadonlyArray<infer A>
? A
: never,
E,
R
>
Creates a stream from a array-emitting Channel.
Example (Creating a stream from an array-emitting channel)
import { Channel, Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const channel = Channel.succeed([1, 2, 3] as const)
const stream = Stream.fromChannel(channel)
const result = yield* Stream.runCollect(stream)
yield* Console.log(result)
})
// Output: [ 1, 2, 3 ]
fromChannel(import ChannelChannel.failSync(evaluate: LazyArg<E>evaluate))