Skip to content

whenIsBoolTruthy

Callback executed only for EitherBoolTruthy values. Otherwise, the initial value is returned.

Interactive example

Syntax

Classic signature

typescript
function whenIsBoolTruthy<
  const GenericInput extends unknown,
  const GenericOutput extends AnyValue | EscapeVoid
>(
  input: GenericInput,
  theFunction: (value: Unwrap<Extract<ToEither<GenericInput>, EitherBoolTruthy>>) => GenericOutput
): GenericOutput | Exclude<ToEither<GenericInput>, EitherBoolTruthy>;

Curried signature

typescript
function whenIsBoolTruthy<
  const GenericInput extends unknown,
  const GenericOutput extends AnyValue | EscapeVoid
>(
  theFunction: (value: Unwrap<Extract<ToEither<GenericInput>, EitherBoolTruthy>>) => GenericOutput
): (input: GenericInput) => GenericOutput | Exclude<ToEither<GenericInput>, EitherBoolTruthy>;

Parameters

  • theFunction: Function executed only when the value is truthy.
  • input: Value or Either to process (optional in the curried version).

Return value

The result of theFunction for truthy values, otherwise the original value (EitherBoolFalsy).

See also

Released under the MIT license.