<E>(cause: Cause.Cause<E>): Stream<never, E>Creates a stream that fails with the specified Cause.
Example (Failing with a cause)
import { Cause, Console, Effect, Stream } from "effect"
const stream = Stream.failCause(Cause.fail("Database connection failed")).pipe(
Stream.catchCause(() => Stream.succeed("recovered"))
)
const program = Effect.gen(function*() {
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
// Output: [ "recovered" ]
})
Effect.runPromise(program)export const const failCause: <E>(
cause: Cause.Cause<E>
) => Stream<never, E>
Creates a stream that fails with the specified Cause.
Example (Failing with a cause)
import { Cause, Console, Effect, Stream } from "effect"
const stream = Stream.failCause(Cause.fail("Database connection failed")).pipe(
Stream.catchCause(() => Stream.succeed("recovered"))
)
const program = Effect.gen(function*() {
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
// Output: [ "recovered" ]
})
Effect.runPromise(program)
failCause = <function (type parameter) E in <E>(cause: Cause.Cause<E>): Stream<never, E>E>(cause: Cause.Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause: import CauseCause.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <E>(cause: Cause.Cause<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>(cause: Cause.Cause<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.const failCause: <E>(
cause: Cause.Cause<E>
) => Channel<never, E, never>
Constructs a channel that fails immediately with the specified Cause.
When to use
Use when the channel failure must preserve a full Cause, such as defects,
interruptions, or combined failures.
Example (Failing with causes)
import { Cause, Channel } from "effect"
// Create a channel that fails with a simple cause
const simpleCause = Cause.fail("Simple error")
const failedChannel = Channel.failCause(simpleCause)
// Create a channel with a die cause
const dieCause = Cause.die(new Error("System error"))
const dieFailure = Channel.failCause(dieCause)
// Create a channel with a simple fail cause
const failCause = Cause.fail("Simple error")
const simpleFail = Channel.failCause(failCause)
failCause(cause: Cause.Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause))