variable / @typed/guard

bindTo

Wraps any matched output in a new object under key. This is the explicit transition from an arbitrary output to the record-building workflow.

Package version
1.0.0-beta.13
Category
Record construction
Since
1.0.0

Import

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

Signatures

export declare const bindTo: {
    <K extends PropertyKey>(key: K): <I, O, E, R>(guard: GuardInput<I, O, E, R>) => Guard<I, {
        [k in K]: O;
    }, E, R>;
    <I, O, E, R, K extends PropertyKey>(guard: GuardInput<I, O, E, R>, key: K): Guard<I, {
        [k in K]: O;
    }, E, R>;
};

Why

Explicit wrapping makes arbitrary values safe for record combinators without assuming their runtime shape.

Ownership and lifetime

This pure combinator acquires no resources and creates a fresh plain object for every match.

Examples

import { bindTo, liftPredicate } from "@typed/guard"
const named = bindTo(liftPredicate(Boolean), "value")

Source