iter-tools-es
Version:
The iterable toolbox
35 lines (29 loc) • 772 B
JavaScript
const {
iterableCurry
} = require('../../internal/iterable.js');
const {
CircularBuffer,
ReadOnlyCircularBuffer
} = require('../../internal/circular-buffer.js');
function* __windowBehind(source, size, {
filler
} = {}) {
const buffer = new CircularBuffer(size);
const bufferReadProxy = new ReadOnlyCircularBuffer(buffer);
buffer.fill(filler);
for (const value of source) {
buffer.push(value);
yield bufferReadProxy;
}
}
exports.__windowBehind = __windowBehind;
const windowBehind = /*#__PURE__*/iterableCurry(__windowBehind, {
minArgs: 1,
maxArgs: 2,
validateArgs(args) {
if (typeof args[1] !== 'number') {
throw new Error(`${'windowBehind'} must be passed a numeric size`);
}
}
});
exports.windowBehind = windowBehind;