picomath/complex/extendByComplex.js
Glen Whitney e5ec1083e3 feat: Selective loader that extends all/only existing number methods to complex
Plus a test example where an instance is initialized to have only addition,
  and then that instance is extended to complex numbers, at which point it
  has number and complex addition but not negation or subtraction (at all).
2022-03-25 02:46:49 -07:00

24 lines
636 B
JavaScript

import { isTF } from '../poortf.js'
import createComplex from './complex.js'
/* Add all the complex methods for the number methods that are
* already in the instance: */
export default async function extend(pmath) {
for (const item in pmath) {
if (isTF(pmath[item])) {
// might be a number method, try importing
const modulePath = `./${item}.js`
try {
const { default: create } = await import(modulePath)
create(pmath)
} catch (err) {
// Guess it wasn't a number method; no worries
}
}
}
createComplex(pmath)
}