Skip to content

whenIsNullableFilled

Applies a function only when the nullable Either contains a value (NullableFilled).

Interactive example

Syntax

Classic signature

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

Curried signature

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

Parameters

  • theFunction: Callback executed when the value is present.
  • input: Value/Either to inspect.

Return value

Result of the callback if the value exists, otherwise the initial value (NullableEmpty).

See also

Released under the MIT license.