variable / @typed/guard

map

Maps matched output synchronously while preserving non-match and Effect channels.

Package version
1.0.0-beta.13
Category
Value transformations
Since
1.0.0

Import

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

Signatures

export declare const map: {
    <O, B>(f: (o: O) => B): <I, R, E>(guard: GuardInput<I, O, E, R>) => Guard<I, B, E, R>;
    <I, O, E, R, B>(guard: GuardInput<I, O, E, R>, f: (o: O) => B): Guard<I, B, E, R>;
};

Why

Pure output adaptation should not add errors or services and should never run for None.

Ownership and lifetime

Construction acquires no resources; the callback runs once for each Some during Effect execution.

Examples

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

Source