iterable-lookahead
Version:
Iterable wrapper that add methods to read ahead or behind current item.
55 lines (37 loc) • 1.36 kB
Markdown
# iterable-lookahead
[](https://greenkeeper.io/)
[](http://travis-ci.org/parro-it/iterable-lookahead)
[](https://coveralls.io/github/parro-it/iterable-lookahead)
[](https://npmjs.org/package/iterable-lookahead)
[](https://npmjs.org/package/iterable-lookahead)
> Iterable wrapper that add methods to read ahead or behind current item.
# Installation
```bash
npm install --save iterable-lookahead
```
## Usage
```js
const lookahead = require('iterable-lookahead');
const iterable = lookahead([1, 2, 3, 4]);
for (const item of iterable) {
console.log({
item,
ahead: iterable.ahead(1),
behind: iterable.behind(1)
});
}
```
or otherwise, using array spread syntax:
```js
const lookahead = require('iterable-lookahead');
for (const [item, look] of lookahead.spread([1, 2, 3, 4])) {
console.log({
item,
ahead: look.ahead(1),
behind: look.behind(1)
});
}
```
# License
The MIT License (MIT)
Copyright (c) 2016 Andrea Parodi