matchWithNumber
matchWithNumber() performs exhaustive pattern matching on the value of a Clean number primitive. Every possible value must have a processing branch.
A Clean primitive is a wrapped object, so it cannot be used directly as a matcher key. The keys are therefore raw number values. When a key matches, its callback receives the original Clean primitive narrowed to that value, preserving its Primitive, ConstrainedType, or NewType information.
Interactive example
Syntax
Classic signature
typescript
function matchWithNumber<Input extends Primitive<number>, Matcher>(
input: Input,
matcher: Matcher
): ReturnType<Matcher[keyof Matcher]>Curried signature
typescript
function matchWithNumber<Input extends Primitive<number>, Matcher>(
matcher: Matcher
): (input: Input) => ReturnType<Matcher[keyof Matcher]>Parameters
input: a Clean primitive containing anumber, including constrained values and new types.matcher: an exhaustive object indexed by the possible rawnumbervalues. A broadPrimitive<number>requires an indexedRecord<number, handler>.
Every key must have exactly one handler. TypeScript rejects a missing key or a key outside the input union. The selected handler receives the original Clean object narrowed with Primitive<MatchingValue>.
Return value
The selected handler result, typed as the union of every handler return type.
See also
matchWithString- String primitive equivalent.equal- Compares wrapped primitive values.
