feat(Chain): add computation pipelines like mathjs

Also adds a `mean()` operation so there will be at least one operation
  that takes only a rest parameter, to exercise the ban on splitting
  such a parameter between the stored value and new arguments.
  Adds various tests of chains.

  Resolves #32.
This commit is contained in:
Glen Whitney 2022-08-01 16:24:20 -07:00
parent 46ae7f78ab
commit 814f660000
7 changed files with 100 additions and 14 deletions

View file

@ -4,6 +4,7 @@ export * from './Types/generic.mjs'
export const add = reducingOperation
export {lcm} from './lcm.mjs'
export {mean} from './mean.mjs'
export {mod} from './mod.mjs'
export const multiply = reducingOperation
export {divide} from './divide.mjs'

3
src/generic/mean.mjs Normal file
View file

@ -0,0 +1,3 @@
export const mean = {
'...any': ({add, divide}) => args => divide(add(...args), args.length)
}

View file

@ -1,13 +0,0 @@
export * from './Types/generic.mjs'
export const multiply = {
'undefined': () => u => u,
'undefined,...any': () => (u, rest) => u,
any: () => x => x,
'any,undefined': () => (x, u) => u,
'any,any,...any': ({self}) => (a,b,rest) => {
const later = [b, ...rest]
return later.reduce((x,y) => self(x,y), a)
}
}