2025-04-08 23:25:01 +00:00
|
|
|
import {Returns} from '#core/Type.js'
|
2025-04-24 13:09:15 -07:00
|
|
|
import {match, Any} from '#core/TypePatterns.js'
|
2025-04-08 23:25:01 +00:00
|
|
|
|
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
|
|
|
export const square = match(Any, (math, T) => {
|
2025-04-08 23:25:01 +00:00
|
|
|
const mult = math.multiply.resolve([T, T])
|
|
|
|
return Returns(mult.returns, a => mult(a, a))
|
|
|
|
})
|