/function/when
stdRuns the given function only when the condition is met.
Type signature
(predicate: (...xs: unknown[]) => boolean) => (action: (...xs: unknown[]) => unknown) => (...args: unknown[]) => unknown
Examples
when((x) => x > 0)((x) =>
console.log(x),
)(5);
when((x) => x > 0)((x) =>
console.log(x),
)(-3);
Try in REPL
Questions
- How to run a function only when a condition is satisfied?