function / @typed/guard

liftPredicate

Builds a Guard from a predicate or refinement. The predicate is evaluated only when the returned Effect runs. A thrown exception becomes an Effect defect; use an effectful Guard when failure belongs in the typed error channel.

Package version
1.0.0-beta.7
Category
Input selection
Since
1.0.0

Import

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

Signatures

export declare function liftPredicate<A, B extends A>(predicate: Predicate.Refinement<A, B>): Guard<A, B>;
export declare function liftPredicate<A>(predicate: Predicate.Predicate<A>): Guard<A, A>;

Why

Predicate lifting is the bridge from synchronous refinements into deferred Guard composition while preserving the None versus failure distinction.

Ownership and lifetime

Construction acquires no resources; the predicate runs once per invocation when the returned Effect executes.

Examples

import { liftPredicate } from "@typed/guard"
const string = liftPredicate((value: unknown): value is string => typeof value === "string")

Source