@monstermann/fn
Version:
A utility library for TypeScript.
32 lines • 772 B
TypeScript
//#region src/function/ifElse.d.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
* ```
*/
declare const ifElse: {
<T, A, B>(predicate: (value: NoInfer<T>) => boolean, onTrue: (value: NoInfer<T>) => A, onFalse: (value: NoInfer<T>) => B): (value: T) => A | B;
<T, A, B>(value: T, predicate: (value: NoInfer<T>) => boolean, onTrue: (value: NoInfer<T>) => A, onFalse: (value: NoInfer<T>) => B): A | B;
};
//#endregion
export { ifElse };