<A, L = never>(
a: A,
leftovers?: NonEmptyReadonlyArray<L> | undefined
): Sink<A, unknown, L>A sink that immediately ends with the specified value.
Example (Succeeding with a value)
import { Effect, Sink, Stream } from "effect"
// Create a sink that always yields the same value
const sink = Sink.succeed(42)
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).then(console.log)
// Output: 42export const const succeed: <A, L = never>(
a: A,
leftovers?: NonEmptyReadonlyArray<L> | undefined
) => Sink<A, unknown, L>
A sink that immediately ends with the specified value.
Example (Succeeding with a value)
import { Effect, Sink, Stream } from "effect"
// Create a sink that always yields the same value
const sink = Sink.succeed(42)
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).then(console.log)
// Output: 42
succeed = <function (type parameter) A in <A, L = never>(a: A, leftovers?: NonEmptyReadonlyArray<L> | undefined): Sink<A, unknown, L>A, function (type parameter) L in <A, L = never>(a: A, leftovers?: NonEmptyReadonlyArray<L> | undefined): Sink<A, unknown, L>L = never>(a: Aa: function (type parameter) A in <A, L = never>(a: A, leftovers?: NonEmptyReadonlyArray<L> | undefined): Sink<A, unknown, L>A, leftovers: NonEmptyReadonlyArray<L> | undefinedleftovers?: type NonEmptyReadonlyArray<A> = readonly [A, ...A[]]A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) L in <A, L = never>(a: A, leftovers?: NonEmptyReadonlyArray<L> | undefined): Sink<A, unknown, L>L> | undefined): 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<function (type parameter) A in <A, L = never>(a: A, leftovers?: NonEmptyReadonlyArray<L> | undefined): Sink<A, unknown, L>A, unknown, function (type parameter) L in <A, L = never>(a: A, leftovers?: NonEmptyReadonlyArray<L> | undefined): Sink<A, unknown, L>L> =>
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 succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed([a: Aa, leftovers: NonEmptyReadonlyArray<L> | undefinedleftovers]))