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:
parent
46ae7f78ab
commit
814f660000
7 changed files with 100 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/* Core of pocomath: create an instance */
|
||||
import typed from 'typed-function'
|
||||
import dependencyExtractor from './dependencyExtractor.mjs'
|
||||
import {makeChain} from './Chain.mjs'
|
||||
import {subsetOfKeys, typesOfSignature} from './utils.mjs'
|
||||
|
||||
const anySpec = {} // fixed dummy specification of 'any' type
|
||||
|
|
@ -21,6 +22,7 @@ export default class PocomathInstance {
|
|||
* must be added to this list.
|
||||
*/
|
||||
static reserved = new Set([
|
||||
'chain',
|
||||
'config',
|
||||
'importDependencies',
|
||||
'install',
|
||||
|
|
@ -64,6 +66,7 @@ export default class PocomathInstance {
|
|||
return true // successful
|
||||
}
|
||||
})
|
||||
this._chainRepository = {} // place to store chainified functions
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,6 +167,11 @@ export default class PocomathInstance {
|
|||
return result
|
||||
}
|
||||
|
||||
/* Return a chain object for this instance with a given value: */
|
||||
chain(value) {
|
||||
return makeChain(value, this, this._chainRepository)
|
||||
}
|
||||
|
||||
_installInstance(other) {
|
||||
for (const [type, spec] of Object.entries(other.Types)) {
|
||||
if (type === 'any' || this._templateParam(type)) continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue