whenIsRightOtherwise
Applies one callback on Right values and a second callback on every non-Right value.
Interactive example
Syntax
Classic signature
typescript
function whenIsRightOtherwise<
GenericInput extends unknown,
GenericOutputRight,
GenericOutputOtherwise
>(
input: GenericInput,
theFunction: (value: Unwrap<Extract<GenericInput, Right>>) => GenericOutputRight,
otherwiseFunction: (value: Extract<GenericInput, Left> | Exclude<GenericInput, Right | Left>) => GenericOutputOtherwise
): GenericOutputRight | GenericOutputOtherwise;Curried signature
typescript
function whenIsRightOtherwise<
GenericInput extends unknown,
GenericOutputRight,
GenericOutputOtherwise
>(
theFunction: (value: Unwrap<Extract<GenericInput, Right>>) => GenericOutputRight,
otherwiseFunction: (value: Extract<GenericInput, Left> | Exclude<GenericInput, Right | Left>) => GenericOutputOtherwise
): (input: GenericInput) => GenericOutputRight | GenericOutputOtherwise;Parameters
theFunction: Callback executed when input isRight(receives unwrapped payload).otherwiseFunction: 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 otherwiseFunction.
See also
whenIsLeftOtherwise- Symmetric variant forLeft.whenIsRight- Right-only mapping without explicit otherwise.
