feat: respect return typing strategy for all generic functions
This commit is contained in:
parent
c42249e561
commit
793dd361a6
5 changed files with 20 additions and 11 deletions
|
@ -1,8 +1,10 @@
|
|||
import {ReturnsAs} from './helpers.js'
|
||||
import {Returns} from '#core/Type.js'
|
||||
import {Returns, ReturnTyping} from '#core/Type.js'
|
||||
import {Any, Passthru, match, matched} from '#core/TypePatterns.js'
|
||||
import {boolnum} from '#number/helpers.js'
|
||||
|
||||
const {full} = ReturnTyping
|
||||
|
||||
export const equal = match([Any, Any], (math, [T, U]) => {
|
||||
// Finding the correct signature of `indistinguishable` to use for
|
||||
// testing (approximate) equality is tricky, because T or U might
|
||||
|
@ -12,7 +14,7 @@ export const equal = match([Any, Any], (math, [T, U]) => {
|
|||
// the matching type, and then we look up with tolerances.
|
||||
let exactChecker
|
||||
try {
|
||||
exactChecker = math.indistinguishable.resolve([T, U])
|
||||
exactChecker = math.indistinguishable.resolve([T, U], full)
|
||||
} catch { // can't compare, so no way they can be equal
|
||||
return boolnum(() => false)(math)
|
||||
}
|
||||
|
@ -25,7 +27,7 @@ export const equal = match([Any, Any], (math, [T, U]) => {
|
|||
const {relTol, absTol} = typeConfig
|
||||
const RT = math.typeOf(relTol)
|
||||
const AT = math.typeOf(absTol)
|
||||
const approx = math.indistinguishable.resolve([T, U, RT, AT])
|
||||
const approx = math.indistinguishable.resolve([T, U, RT, AT], full)
|
||||
return ReturnsAs(
|
||||
approx, (t, u) => approx(t, u, relTol, absTol))
|
||||
} catch {} // fall through to case with no tolerances
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue