0.1.0 • Published 6 years ago

circular-iterable-array v0.1.0

Weekly downloads
6
License
-
Repository
github
Last release
6 years ago

circular-iterable-array

Yet another circular array. This one extends the Array and overrides its Symbol.iterator method for an infinite (and circular) for...of loop (use with caution!).

Install

npm i circular-iterable-array

Usage

const Circular = require('circular-iterable-array')
const circular = new Circular(1, 2, 3)
// Use just like an Array
circular.push(4)
circular.pop()
console.log(circular) // => [1, 2, 3]
for (const item of circular) {
  console.log(item)
}
// =>
1
2
3
1
2
3
... (infinite loop)

While the for...or loop can still be controlled (break/return when needed)...

CAUTION

DO NOT EXPAND with spread syntax

[...circular]

It will result block the thread, leak memory, and ultimately crash.