Skip to content

whenIsOptionalFilled ​

Applies a callback only when the optional Either contains a value (OptionalFilled).

Interactive example ​

Syntax ​

Classic signature ​

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

Curried signature ​

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

Parameters ​

  • theFunction: Callback executed when the value is defined.
  • input: Value/Either to process.

Return value ​

Result of the callback or the original value if the optional was empty.

See also ​

Released under the MIT license.