<E>(evaluate: LazyArg<Cause.Cause<E>>): Sink<never, unknown, never, E>Creates a sink halting with a specified lazily evaluated Cause.
Example (Failing with a lazy cause)
import { Cause, Effect, Sink, Stream } from "effect"
// Create a sink that fails with a lazy cause
const sink = Sink.failCauseSync(() => Cause.fail(new Error("Lazy cause")))
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).catch(console.log)
// Output: Error: Lazy causeexport const const failCauseSync: <E>(
evaluate: LazyArg<Cause.Cause<E>>
) => Sink<never, unknown, never, E>
Creates a sink halting with a specified lazily evaluated Cause.
Example (Failing with a lazy cause)
import { Cause, Effect, Sink, Stream } from "effect"
// Create a sink that fails with a lazy cause
const sink = Sink.failCauseSync(() => Cause.fail(new Error("Lazy cause")))
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).catch(console.log)
// Output: Error: Lazy cause
failCauseSync = <function (type parameter) E in <E>(evaluate: LazyArg<Cause.Cause<E>>): Sink<never, unknown, never, E>E>(evaluate: LazyArg<Cause.Cause<E>>evaluate: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<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>(evaluate: LazyArg<Cause.Cause<E>>): Sink<never, unknown, never, E>E>>): interface Sink<out A, in In = unknown, out L = never, out E = never, out R = never>A Sink<A, In, L, E, R> is used to consume elements produced by a Stream.
You can think of a sink as a function that will consume a variable amount of
In elements (could be 0, 1, or many), might fail with an error of type E,
and will eventually yield a value of type A together with a remainder of
type L (i.e. any leftovers).
Example (Running a sink with a stream)
import { Effect, Sink, Stream } from "effect"
// Create a simple sink that always succeeds with a value
const sink: Sink.Sink<number> = Sink.succeed(42)
// Use the sink to consume a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).then(console.log)
// Output: 42
Namespace containing types and interfaces for Sink variance and type relationships.
Sink<never, unknown, never, function (type parameter) E in <E>(evaluate: LazyArg<Cause.Cause<E>>): Sink<never, unknown, never, E>E> =>
const fromEffectEnd: <A, E, R, L = never>(
effect: Effect.Effect<End<A, L>, E, R>
) => Sink<A, unknown, L, E, R>
Creates a sink that ignores upstream input and completes from an effect that
already returns an End.
When to use
Use when you need to create a sink from an effect that returns both the sink
result value and optional leftovers.
fromEffectEnd(import EffectEffect.const failCauseSync: <E>(
evaluate: LazyArg<Cause.Cause<E>>
) => Effect<never, E>
Creates an Effect that represents a failure with a Cause computed lazily.
When to use
Use to defer computing a full Cause until the effect is run.
Details
The cause-producing function is evaluated each time the effect is executed.
Example (Lazily creating a Cause)
import { Cause, Effect } from "effect"
const program = Effect.failCauseSync(() =>
Cause.fail("Error computed at runtime")
)
Effect.runPromiseExit(program).then(console.log)
// Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
failCauseSync(evaluate: LazyArg<Cause.Cause<E>>evaluate))