feat: Add (and test) a custom loader for extending existing ops to Complex

This commit is contained in:
Glen Whitney 2022-07-19 12:08:18 -07:00
parent 84a8b9d5c4
commit 92485678f1
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,19 @@
import './Complex.mjs'
import * as complex from './complex.mjs'
/* Add all the complex implementations for functions already
in the instance:
*/
export default async function extendToComplex(pmath) {
pmath.install(complex)
for (const name in pmath._imps) {
const modulePath = `./${name}.mjs`
try {
const mod = await import(modulePath)
pmath.install(mod)
} catch (err) {
// Guess it wasn't a method available in complex; no worries
}
}
}