variable / @typed/fx/Sink

slice

Runs a producer callback through a bounded view of a sink.

Package version
2.0.0-beta.7
Category
Stopping delivery
Since
1.0.0

Import

import { slice } from "@typed/fx/Sink";

Signatures

export declare const slice: {
    <A, E, R, R2>(bounds: Bounds, f: (sink: Sink<A, E, R>) => Effect.Effect<unknown, never, R2>): (sink: Sink<A, E, R>) => Effect.Effect<void, never, R | R2>;
    <A, E, R, R2>(sink: Sink<A, E, R>, bounds: Bounds, f: (sink: Sink<A, E, R>) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;
};

Why

Consumers can skip an initial prefix and stop after a fixed number of values, allowing the surrounding producer work to finish early.

Ownership and lifetime

Each execution owns fresh counters and an early-exit callback. Successes remain ordered; at most take values are delivered after skip values. Failures always pass through. Reaching the bound completes and aborts the callback fiber; negative bounds are not normalized.

Examples

import { Effect } from "effect"
import * as Sink from "@typed/fx/Sink"
const target = Sink.make(Effect.logError, Effect.log)
const program = Sink.slice(target, { skip: 1, take: 2 }, (bounded) => bounded.onSuccess("kept"))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source