Skip to content

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[],
): KeptAsRightOrLeftInput

Curried signature

typescript
function keepAsRightByInformation<
  GenericInput extends unknown,
  GenericInformation extends Information,
>(
  information: GenericInformation | GenericInformation[],
): (input: GenericInput) => KeptAsRightOrLeftInput

Parameters

  • information: Expected literal information, or an array of literal informations that should remain on the Right side.
  • 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

Released under the MIT license.