unwrapByInformation
Unwraps an Either payload when one literal information or one of multiple literal informations matches, otherwise returns the original input unchanged.
Interactive example
Syntax
Classic signature
typescript
function unwrapByInformation<
GenericInput extends unknown,
GenericInformation extends (
GenericInput extends Either
? ReturnType<typeof informationKind.getValue<GenericInput>>
: never
),
>(
input: GenericInput,
information: GenericInformation | GenericInformation[],
): GenericInput extends Kind<typeof informationKind.definition, GenericInformation>
? Unwrap<GenericInput>
: GenericInputCurried signature
typescript
function unwrapByInformation<
GenericInput extends unknown,
const GenericInformation extends (
GenericInput extends Either
? ReturnType<typeof informationKind.getValue<GenericInput>>
: never
),
>(
information: GenericInformation | GenericInformation[],
): (
input: GenericInput,
) => GenericInput extends Kind<typeof informationKind.definition, GenericInformation>
? Unwrap<GenericInput>
: GenericInputParameters
information: Expected literal information, or an array of literal informations.input: Either value to unwrap immediately, or later through the curried form.
Return value
Returns the unwrapped payload when one information matches. If no information matches, returns the original input unchanged.
See also
unwrapByInformationOrThrow– Throwing variant when information does not match.hasInformation– Non-throwing check on literal information.whenHasInformation– Callback-based variant.
