variable / @typed/guard

pipe

Runs output only when input matches. None short-circuits successfully, while failures and service requirements are preserved from both Guards.

Package version
1.0.0-beta.7
Category
Sequential composition
Since
1.0.0

Import

import { pipe } from "@typed/guard";

Signatures

export declare const pipe: {
    <O, B, E2, R2>(output: GuardInput<O, B, E2, R2>): <I, R, E>(input: GuardInput<I, O, E, R>) => Guard<I, B, E | E2, R | R2>;
    <I, O, E, R, B, E2, R2>(input: GuardInput<I, O, E, R>, output: GuardInput<O, B, E2, R2>): Guard<I, B, E | E2, R | R2>;
};

Why

Sequential Guard composition must preserve ordinary non-match while unioning the typed error and service channels of both stages.

Ownership and lifetime

Construction acquires no resources; each invocation runs the first Effect and only starts the second after Some.

Examples

import { liftPredicate, pipe } from "@typed/guard"
const nonEmpty = pipe(liftPredicate((u: unknown): u is string => typeof u === "string"), liftPredicate((s) => s.length > 0))

Source