whenIsRightOtherwise
Applique un callback sur les valeurs Right et un second callback sur toutes les valeurs non-Right.
Exemple interactif
Syntaxe
Signature classique
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;Signature currifiée
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;Paramètres
theFunction: Callback exécuté quand l'entrée estRight(reçoit le payload unwrap).otherwiseFunction: Callback exécuté pour les valeurs restantes (Leftou non-Either), sans unwrap.input: Valeur à traiter immédiatement (optionnelle en style currifié).
Valeur de retour
Renvoie le résultat de theFunction pour un Right, sinon le résultat de otherwiseFunction.
Voir aussi
whenIsLeftOtherwise- Variante symétrique pourLeft.whenIsRight- Mapping côté Right sans branche otherwise explicite.
