keepAsRightByInformation
Keeps matching Either informations on the Right side and converts every non-matching Right to Left.
When the current information matches and the input is a Left, it is converted to a Right with the same information and payload. When the current information does not match and the input is a Right, it is converted to a Left.
Interactive example
Syntax
Classic signature
typescript
function keepAsRightByInformation<
GenericInput extends unknown,
GenericInformation extends Information,
>(
input: GenericInput,
information: GenericInformation | GenericInformation[],
): KeptAsRightOrLeftInputCurried signature
typescript
function keepAsRightByInformation<
GenericInput extends unknown,
GenericInformation extends Information,
>(
information: GenericInformation | GenericInformation[],
): (input: GenericInput) => KeptAsRightOrLeftInputParameters
information: Expected literal information, or an array of literal informations that should remain on theRightside.input: Either value to normalize immediately, or later through the curried form.
Return value
Returns a Right when the current information is selected, converting a matching Left if needed. Returns a Left when the current information is not selected, converting a non-matching Right if needed. Non-Either values are returned unchanged.
See also
keepAsRightSelection– Exhaustive selector variant.unwrapByInformation– Unwraps matching informations instead of keeping anEither.hasInformation– Type guard based on literal information.
