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