2025-04-16 04:23:48 +00:00
|
|
|
import {ReturnsAs} from './helpers.js'
|
refactor: change onType to match and take only one pattern and result (#22)
Pursuant to #12. Besides changing the name of onType to match, and only allowing one pattern and result in `match()`,
this PR also arranges that in place of an onType with lots of alternating PATTERN, VALUE, PATTERN, VALUE arguments, one now exports an _array_ of `match(PATTERN, VALUE)` items.
Doesn't quite fully resolve #12, because there is still the question of whether `match(...)` can be left out for a behavior that literally matches anything (current behavior), or whether `match(Passthru, behavior)` should be required for such cases.
Reviewed-on: https://code.studioinfinity.org/StudioInfinity/nanomath/pulls/22
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
2025-04-22 05:01:21 +00:00
|
|
|
import {ResolutionError} from '#core/helpers.js'
|
2025-04-16 04:23:48 +00:00
|
|
|
import {Returns} from '#core/Type.js'
|
|
|
|
import {Any} from "#core/TypePatterns.js"
|
|
|
|
|
|
|
|
export const isZero = (math, [T]) => {
|
|
|
|
if (!T) { // called with no arguments
|
|
|
|
throw new ResolutionError('isZero() requires one argument')
|
|
|
|
}
|
|
|
|
const z = math.zero(T)
|
|
|
|
const eq = math.equal.resolve([T, T])
|
|
|
|
return ReturnsAs(eq, x => eq(z, x))
|
|
|
|
}
|