UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

34 lines (32 loc) 604 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/function/ifElse.ts /** * `ifElse(predicate, onTrue, onFalse)` * * Conditionally applies one of two functions based on a predicate result. * * ```ts * ifElse( * 5, * (x) => x > 3, * (x) => x * 2, * (x) => x * 3, * ); // 10 * ``` * * ```ts * pipe( * 5, * ifElse( * (x) => x > 3, * (x) => x * 2, * (x) => x * 3, * ), * ); // 10 * ``` */ const ifElse = dfdlT((value, predicate, onTrue, onFalse) => { return predicate(value) ? onTrue(value) : onFalse(value); }, 4); //#endregion export { ifElse };