Skip to content

whenIsNullishEmpty ​

Applies a callback only when the Either is NullishEmpty.

Interactive example ​

Syntax ​

Classic signature ​

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

Curried signature ​

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

Parameters ​

  • theFunction: Callback executed in case of absence.
  • input: Either or compatible value (optional in the curried version).

Return value ​

Result of the callback if NullishEmpty, otherwise the original value.

See also ​

Released under the MIT license.