From cf8ad1edfca87f1f12fe113e4eaf0b803b2542fc Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Fri, 22 Jul 2022 13:40:40 -0700 Subject: [PATCH] chore: Remove complex 'base cases' that are no longer needed --- src/complex/add.mjs | 12 +++--------- src/complex/negate.mjs | 5 +---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/complex/add.mjs b/src/complex/add.mjs index fa65404..3583b38 100644 --- a/src/complex/add.mjs +++ b/src/complex/add.mjs @@ -1,16 +1,10 @@ -import {Types, numComplex} from './Types/Complex.mjs' +export {Types} from './Types/Complex.mjs' -export {Types} 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) => { - /* Need a "base case" to avoid infinite self-reference loops */ - if (numComplex(z) && numComplex(w)) { - return {re: w.re + z.re, im: w.im + z.im} - } - return {re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)} - }, seed) + return addends.reduce((w,z) => + ({re: ref.self(w.re, z.re), im: ref.self(w.im, z.im)}), seed) }] } diff --git a/src/complex/negate.mjs b/src/complex/negate.mjs index 04436a3..bf4e612 100644 --- a/src/complex/negate.mjs +++ b/src/complex/negate.mjs @@ -1,10 +1,7 @@ -import {Types, numComplex} from './Types/Complex.mjs' +export {Types} from './Types/Complex.mjs' -export {Types} export const negate = { Complex: [['self'], ref => z => { - /* need a "base case" to avoid infinite self-reference */ - if (numComplex(z)) return {re: -z.re, im: -z.im} return {re: ref.self(z.re), im: ref.self(z.im)} }] }