whenIsOptionalEmpty
Applies a function only when an optional is empty (undefined).
Interactive example
Syntax
Classic signature
typescript
function whenIsOptionalEmpty<
const GenericInput extends unknown,
const GenericOutput extends AnyValue | EscapeVoid
>(
input: GenericInput,
theFunction: (value: Unwrap<Extract<ToEither<GenericInput>, EitherOptionalEmpty>>) => GenericOutput
): GenericOutput | Exclude<ToEither<GenericInput>, EitherOptionalEmpty>;Curried signature
typescript
function whenIsOptionalEmpty<
const GenericInput extends unknown,
const GenericOutput extends AnyValue | EscapeVoid
>(
theFunction: (value: Unwrap<Extract<ToEither<GenericInput>, EitherOptionalEmpty>>) => GenericOutput
): (input: GenericInput) => GenericOutput | Exclude<ToEither<GenericInput>, EitherOptionalEmpty>;Parameters
theFunction: Callback executed if the value isundefined.input: Value/Either to analyze.
Return value
Result of the callback if empty, otherwise the initial value.
