UNPKG

@thi.ng/dsp

Version:

Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils

85 lines (84 loc) 1.64 kB
import { illegalArity } from "@thi.ng/errors/illegal-arity"; import { AGen } from "./agen.js"; function mapG(op, ...args) { switch (args.length) { case 2: return new MapG1(op, args[0], args[1]); case 3: return new MapG2(op, args[0], args[1], args[2]); case 4: return new MapG3(op, args[0], args[1], args[2], args[3]); case 5: return new MapG4(op, args[0], args[1], args[2], args[3], args[4]); default: illegalArity(args.length); } } class MapG1 extends AGen { constructor(_op, _a, init) { super(init); this._op = _op; this._a = _a; } next() { return this._val = this._op(this._a.next(), this._val); } } class MapG2 extends AGen { constructor(_op, _a, _b, init) { super(init); this._op = _op; this._a = _a; this._b = _b; } next() { return this._val = this._op( this._a.next(), this._b.next(), this._val ); } } class MapG3 extends AGen { constructor(_op, _a, _b, _c, init) { super(init); this._op = _op; this._a = _a; this._b = _b; this._c = _c; } next() { return this._val = this._op( this._a.next(), this._b.next(), this._c.next(), this._val ); } } class MapG4 extends AGen { constructor(_op, _a, _b, _c, _d, init) { super(init); this._op = _op; this._a = _a; this._b = _b; this._c = _c; this._d = _d; } next() { return this._val = this._op( this._a.next(), this._b.next(), this._c.next(), this._d.next(), this._val ); } } export { MapG1, MapG2, MapG3, MapG4, mapG };