refactor: Switch to 'map-like object keyed by string and type vector' format
See https://code.studioinfinity.org/glen/nanomath/wiki/Item-Specifications. Also stubs out the TypeDispatcher, mocking the merge function, so we can see that all of the proper things will be added. Ready for initial implementation of the TypeDispatcher.
This commit is contained in:
parent
040ec377a1
commit
69ef928b6e
10 changed files with 84 additions and 15 deletions
|
@ -1,3 +1,3 @@
|
|||
export const Number = {
|
||||
test: n => typeof n === 'number'
|
||||
}
|
||||
import {Type} from '../core/Type.js'
|
||||
|
||||
export const Number = new Type(n => typeof n === 'number')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {plain} from './tools.js'
|
||||
import {plain} from './helpers.js'
|
||||
|
||||
export const abs = plain(Math.abs)
|
||||
export const absquare = plain(a => a*a)
|
||||
|
|
5
src/number/helpers.js
Normal file
5
src/number/helpers.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
import {Returns, onType} from '../core/helpers.js'
|
||||
import {Number} from './Number.js'
|
||||
|
||||
export const plain = f => onType(
|
||||
Array(f.length).fill(Number), Returns(Number, f))
|
|
@ -1,4 +0,0 @@
|
|||
import {Number} from "./Number.js"
|
||||
|
||||
export const plain = f =>
|
||||
[Array(f.length).fill(Number), {returns: Number, behavior: f}]
|
|
@ -1,4 +1,4 @@
|
|||
import {plain} from './tools.js'
|
||||
import {plain} from './helpers.js'
|
||||
|
||||
// Not much to do so far when there is only one type
|
||||
export const number = plain(a => a)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import {plain} from './tools.js'
|
||||
import {plain} from './helpers.js'
|
||||
|
||||
export const clone = plain(a => a)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue