Skip to content

whenIsLeftOtherwise

Applique un callback sur les valeurs Left et un second callback sur toutes les valeurs non-Left.

Exemple interactif

Syntaxe

Signature classique

typescript
function whenIsLeftOtherwise<
  GenericInput extends unknown,
  GenericOutputLeft,
  GenericOutputOtherwise
>(
  input: GenericInput,
  theFunction: (value: Unwrap<Extract<GenericInput, Left>>) => GenericOutputLeft,
  otherwiseFunction: (value: Extract<GenericInput, Right> | Exclude<GenericInput, Right | Left>) => GenericOutputOtherwise
): GenericOutputLeft | GenericOutputOtherwise;

Signature currifiée

typescript
function whenIsLeftOtherwise<
  GenericInput extends unknown,
  GenericOutputLeft,
  GenericOutputOtherwise
>(
  theFunction: (value: Unwrap<Extract<GenericInput, Left>>) => GenericOutputLeft,
  otherwiseFunction: (value: Extract<GenericInput, Right> | Exclude<GenericInput, Right | Left>) => GenericOutputOtherwise
): (input: GenericInput) => GenericOutputLeft | GenericOutputOtherwise;

Paramètres

  • theFunction : Callback exécuté quand l'entrée est Left (reçoit le payload unwrap).
  • otherwiseFunction : Callback exécuté pour les valeurs restantes (Right ou non-Either), sans unwrap.
  • input : Valeur à traiter immédiatement (optionnelle en style currifié).

Valeur de retour

Renvoie le résultat de theFunction pour un Left, sinon le résultat de otherwiseFunction.

Voir aussi

Diffusé sous licence MIT.