feat: add built-in typeOf operator to PocomathInstance

This commit is contained in:
Glen Whitney 2022-07-31 21:26:16 -07:00
parent 7bbdc049ce
commit 1076c3c727
2 changed files with 21 additions and 1 deletions

View file

@ -26,6 +26,7 @@ export default class PocomathInstance {
'install',
'installType',
'name',
'typeOf',
'Types',
'undefinedTypes'
])
@ -153,7 +154,13 @@ export default class PocomathInstance {
if (type === 'any' || this._templateParam(type)) continue
this.installType(type, spec)
}
this._installFunctions(other._imps)
const migrateImps = {}
for (const operator in other._imps) {
if (operator != 'typeOf') { // skip the builtin, we already have it
migrateImps[operator] = other._imps[operator]
}
}
this._installFunctions(migrateImps)
}
/**
@ -305,6 +312,10 @@ export default class PocomathInstance {
// rebundle anything that uses the new type:
this._invalidateDependents(':' + type)
// update the typeOf function
const imp = {}
imp[type] = {uses: new Set(), does: () => () => type}
this._installFunctions({typeOf: imp})
}
/* Returns a list of all types that have been mentioned in the