Skip to content

when

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

Defined in: Composition/when.ts:19

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

A

B

C

(value) => value is B

(value) => C

(value) => C | Exclude<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

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

Defined in: Composition/when.ts:23

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

A

B = A

(value) => boolean

(value) => B

<V>(value) => B | V

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