Skip to content

whenIsBoolFalsy ​

Applies a callback only when the boolean value is falsy.

Interactive example ​

Syntax ​

Classic signature ​

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

Curried signature ​

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

Parameters ​

  • theFunction: Callback executed when the value is falsy.
  • input: Immediate input (optional in the curried version).

Return value ​

Result of the callback for falsy cases, otherwise the original truthy value.

See also ​

Released under the MIT license.