UNPKG

@thi.ng/dsp

Version:

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

35 lines (34 loc) 668 B
import { __take } from "./internal/take.js"; const iterable = (src, initial) => new $Iterable(src, initial); class $Iterable { _iter; _val; constructor(src, initial) { this._iter = src[Symbol.iterator](); this._val = initial; } deref() { return this._val; } *[Symbol.iterator]() { while (true) yield this.next(); } next() { if (this._iter) { const res = this._iter.next(); if (!res.done) { this._val = res.value; } else { this._iter = null; } } return this._val; } take(num, out = [], idx = 0) { return __take(this, num, out, idx); } } export { $Iterable, iterable };