feat: config and approximate equality
All checks were successful
/ test (pull_request) Successful in 17s
All checks were successful
/ test (pull_request) Successful in 17s
Establishes a global config object for a TypeDispatcher instance, so far with just properties representing comparison tolerances. Begins a "relational" group of functions with basic approximate equality, and an initial primitive ordering comparison. Ensures that methods that depend on properties of `config` will be properly updated when those properties change.
This commit is contained in:
parent
27fa4b0193
commit
d3f2bc09b7
19 changed files with 496 additions and 175 deletions
|
@ -6,4 +6,11 @@ import {Returns} from '#core/Type.js'
|
|||
export const plain = f => onType(
|
||||
Array(f.length).fill(NumberT), Returns(NumberT, f))
|
||||
|
||||
export const boolnum = Returns(NumberT, p => p ? 1 : 0)
|
||||
// Takes a behavior returning boolean, and returns a factory
|
||||
// that returns that behavior if the boolean type is present,
|
||||
// and otherwise wraps the behavior to return 1 or 0.
|
||||
export const boolnum = behavior => math => {
|
||||
const {BooleanT} = math.types
|
||||
if (BooleanT) return Returns(BooleanT, behavior)
|
||||
return Returns(NumberT, (...args) => behavior(...args) ? 1 : 0)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue