UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

32 lines (30 loc) 710 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/option/map.ts /** * `map(target, map)` * * Applies a mapping function to a value if it's not `null` or `undefined`. If the target value is `null` or `undefined`, it returns the target unchanged. Otherwise, it applies the mapping function and returns the result. * * ```ts * map(5, (x) => x * 2); // 10 * map(null, (x) => x * 2); // null * map(undefined, (x) => x * 2); // undefined * ``` * * ```ts * pipe( * 5, * map((x) => x * 2), * ); // 10 * pipe( * null, * map((x) => x * 2), * ); // null * ``` */ const map = dfdlT((target, map$1) => { if (target == null) return target; return map$1(target); }, 2); //#endregion export { map };