circular-iterable
Create circular, iterable data structures in JS.
Transpiling
NB This library is written in ES2015 and implements the iterable and iterator protocols and also makes use of a generator function. As such you will either need to be using an ES2015 runtime or transpiling your code.
If using Babel then ensure you have the babel-runtime
package installed. This module should work with babelify
with no further configuration. If using in node Babel will not transpile node_modules by default and you will have to modify its ignore regex, check out the docs for more info, here is a CLI example:
babel-node --ignore node_modules\/!circular-iterable/
Installation
npm i -S circular-iterable
API
Import
;
Create
const circularData = ; // alternatively:const circularDataFromArray = ;
Access Data
; // => 2; // => 3; // => 1; // => 2; // => 3; // => 1; // => 2; // => 2; // => 3
Create Iterators
const iterator = circularDataSymboliterator;iteratornext; // => {value: 1, done: false}iteratornext; // => {value: 2, done: false}iteratornext; // => {value: 3, done: false}iteratornext; // => {value: 1, done: false}iteratornext; // => {value: 2, done: false}// ad infinitum... // state of iterators is kept separate:const newIterator = circularDataSymboliterator;newIteratornext; // => {value: 1, done: false}iteratornext; // => {value: 3, done: false}
toArray
circularData; // => [1, 2, 3]
Transducer Example
;; const circularData = ;const transducer = ;; // => [3, 6, 9, 3, 6]
Implementation
There is no deep cloning of elements passed to circular-iterable so mutate them at your own peril.