whenIsLeftElse
Applies one callback on Left values and a second callback on every non-Left value.
Interactive example
Syntax
Classic signature
typescript
function whenIsLeftElse<
GenericInput extends unknown,
GenericOutputLeft,
GenericOutputElse
>(
input: GenericInput,
theFunction: (value: Unwrap<Extract<GenericInput, Left>>) => GenericOutputLeft,
elseFunction: (value: Extract<GenericInput, Right> | Exclude<GenericInput, Right | Left>) => GenericOutputElse
): GenericOutputLeft | GenericOutputElse;Curried signature
typescript
function whenIsLeftElse<
GenericInput extends unknown,
GenericOutputLeft,
GenericOutputElse
>(
theFunction: (value: Unwrap<Extract<GenericInput, Left>>) => GenericOutputLeft,
elseFunction: (value: Extract<GenericInput, Right> | Exclude<GenericInput, Right | Left>) => GenericOutputElse
): (input: GenericInput) => GenericOutputLeft | GenericOutputElse;Parameters
theFunction: Callback executed when input isLeft(receives unwrapped payload).elseFunction: Callback executed for remaining values (Rightor non-Either), without unwrap.input: Value to process immediately (optional in curried style).
Return value
Returns the result of theFunction for Left, otherwise the result of elseFunction.
See also
whenIsRightElse- Symmetric variant forRight.whenIsLeft- Left-only mapping without explicit else.
