UNPKG

@thi.ng/transducers

Version:

Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations

17 lines (16 loc) 247 B
function* cycle(input, num = Infinity) { if (num < 1) return; let cache = []; for (const i of input) { cache.push(i); yield i; } if (cache.length > 0) { while (--num > 0) { yield* cache; } } } export { cycle };