keepAsRightByInformation
Conserve les informations Either correspondantes côté Right et convertit chaque Right non correspondant en Left.
Lorsque l'information courante correspond et que l'entrée est un Left, elle est convertie en Right avec la même information et le même payload. Lorsque l'information courante ne correspond pas et que l'entrée est un Right, elle est convertie en Left.
Exemple interactif
Syntaxe
Signature classique
typescript
function keepAsRightByInformation<
GenericInput extends unknown,
GenericInformation extends Information,
>(
input: GenericInput,
information: GenericInformation | GenericInformation[],
): KeptAsRightOrLeftInputSignature currifiée
typescript
function keepAsRightByInformation<
GenericInput extends unknown,
GenericInformation extends Information,
>(
information: GenericInformation | GenericInformation[],
): (input: GenericInput) => KeptAsRightOrLeftInputParamètres
information: Information littérale attendue, ou tableau d'informations littérales qui doivent rester côtéRight.input: Valeur Either à normaliser immédiatement, ou plus tard via la forme currifiée.
Valeur de retour
Retourne un Right quand l'information courante est sélectionnée, en convertissant un Left correspondant si nécessaire. Retourne un Left quand l'information courante n'est pas sélectionnée, en convertissant un Right non correspondant si nécessaire. Les valeurs non-Either sont renvoyées inchangées.
Voir aussi
keepAsRightSelection– Variante à sélecteur exhaustif.unwrapByInformation– Unwrap les informations correspondantes au lieu de conserver unEither.hasInformation– Type guard basé sur l'information littérale.
