variable / @typed/guard

decode

Decodes each matched encoded value through an Effect Schema.

Package version
1.0.0-beta.7
Category
Schema decoding and encoding
Since
1.0.0

Import

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

Signatures

export declare const decode: {
    <S extends Schema.Top>(schema: S): <I, E = never, R = never>(guard: GuardInput<I, S["Encoded"], E, R>) => Guard<I, S["Type"], Schema.SchemaError | E, R | S["DecodingServices"]>;
    <I, E, R, S extends Schema.Top>(guard: GuardInput<I, S["Encoded"], E, R>, schema: S): Guard<I, S["Type"], Schema.SchemaError | E, R | S["DecodingServices"]>;
};

Why

The composed Guard preserves source non-match and errors while adding schema failures and decoding service requirements.

Ownership and lifetime

Construction acquires no resources; decoding starts only for Some and follows that invocation’s lifetime.

Examples

import { decode, liftPredicate } from "@typed/guard"
import { Schema } from "effect"
const number = decode(liftPredicate((u: unknown): u is string => typeof u === "string"), Schema.NumberFromString)

Source