whenIsSelected
Runs a callback on the unwrapped Either payloads selected by an exhaustive information selector and forwards all other inputs unchanged.
The selector maps every possible information of the input union to true or false. A true entry executes the callback with the unwrapped payload; a false entry preserves the original Either.
Interactive example
Syntax
Classic signature
typescript
function whenIsSelected<
GenericInput extends unknown,
GenericSelector extends Record<Information, boolean>,
GenericOutput,
>(
input: GenericInput,
selector: GenericSelector,
theFunction: (value: UnwrappedSelectedInputs) => GenericOutput,
): GenericOutput | UnselectedInputsCurried signature
typescript
function whenIsSelected<
GenericInput extends unknown,
GenericSelector extends Record<Information, boolean>,
GenericOutput,
>(
selector: GenericSelector,
theFunction: (value: UnwrappedSelectedInputs) => GenericOutput,
): (input: GenericInput) => GenericOutput | UnselectedInputsParameters
selector: Exhaustive object mapping every possible input information totrueorfalse.theFunction: Callback receiving the unwrapped payload of the selected informations.input: Value to process immediately, or later through the curried form.
Return value
Returns the callback result when the current information is selected with true. Otherwise, it returns the original input unchanged.
When a selector entry is typed as boolean, the return type includes both the callback result and the original Either for that information.
See also
whenHasInformation- Selects one or several informations without an exhaustive selector.unwrapSelection- Unwraps selected payloads without applying a callback.matchInformation- Exhaustive callback-based matching by information.
