<E>(evaluate: LazyArg<E>): Sink<never, unknown, never, E>A sink that always fails with the specified lazily evaluated error.
Example (Failing with a lazy error)
import { Effect, Sink, Stream } from "effect"
// Create a sink that fails with a lazy error
const sink = Sink.failSync(() => new Error("Lazy error"))
// 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 errorexport const const failSync: <E>(
evaluate: LazyArg<E>
) => Sink<never, unknown, never, E>
A sink that always fails with the specified lazily evaluated error.
Example (Failing with a lazy error)
import { Effect, Sink, Stream } from "effect"
// Create a sink that fails with a lazy error
const sink = Sink.failSync(() => new Error("Lazy error"))
// 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 error
failSync = <function (type parameter) E in <E>(evaluate: LazyArg<E>): Sink<never, unknown, never, E>E>(evaluate: LazyArg<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<function (type parameter) E in <E>(evaluate: LazyArg<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<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 failSync: <E>(
evaluate: LazyArg<E>
) => Effect<never, E>
Creates an Effect that represents a recoverable error using a lazy evaluation.
When to use
Use to defer computing a recoverable error value until the effect is run.
Details
The error-producing function is evaluated each time the effect is executed.
Example (Lazily creating failures)
import { Data, Effect } from "effect"
class ProgramError extends Data.TaggedError("ProgramError")<{ readonly failedAt: Date }> {}
const program = Effect.failSync(() => new ProgramError({ failedAt: new Date() }))
Effect.runPromiseExit(program).then(console.log)
// Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
failSync(evaluate: LazyArg<E>evaluate))