Skip to content

when

when<A, B>(predicate, onTrue): (value) => A | B

Defined in: Composition/when.ts:20

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

A

B = A

(value) => boolean

(value) => B

(value) => A | B

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

pipe(
  3,
  when(n => n % 2 === 0, n => n * 2)
); // 3

unless for executing when a predicate is not met