Skip to content

unless

unless<A, B>(predicate, onFalse): (value) => A | B

Defined in: Composition/unless.ts:20

Executes a function on the piped value if a predicate is NOT met, otherwise returns the value unchanged.

A

B = A

(value) => boolean

(value) => B

(value) => A | B

pipe(
  5,
  unless(n => n % 2 === 0, n => n * 2)
); // 10

pipe(
  4,
  unless(n => n % 2 === 0, n => n * 2)
); // 4

when for executing when a predicate is met