pocomath/src/complex/add.mjs
Glen Whitney 0069597a76 fix: Separate typed instance for each PocomathInstance (#15)
Also starts each PocomathInstance with no types at all, and uses the new
  situation to eliminate the need for a Complex "base case".

  Resolves #14.
  Resolves #13.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: #15
2022-07-22 20:49:14 +00:00

11 lines
315 B
JavaScript

export {Types} from './Types/Complex.mjs'
export const add = {
'...Complex': [['self'], ref => addends => {
if (addends.length === 0) return {re:0, im:0}
const seed = addends.shift()
return addends.reduce((w,z) =>
({re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)}), seed)
}]
}