feat: Template implementations

This commit is contained in:
Glen Whitney 2022-07-31 23:33:58 -07:00
parent 1076c3c727
commit fd3d6b2eb3
9 changed files with 67 additions and 23 deletions

View file

@ -1,10 +1,12 @@
export * from './Types/Complex.mjs'
export const add = {
'...Complex': ({self}) => addends => {
if (addends.length === 0) return {re:0, im:0}
const seed = addends.shift()
return addends.reduce(
(w,z) => ({re: self(w.re, z.re), im: self(w.im, z.im)}), seed)
}
'Complex,number': ({
'self(number,number)': addNum,
'complex(any,any)': cplx
}) => (z,x) => cplx(addNum(z.re, x), z.im),
'Complex,Complex': ({
self,
'complex(any,any)': cplx
}) => (w,z) => cplx(self(w.re, z.re), self(w.im, z.im))
}