iterable-has-next
v0.0.4
Published
Extended iterator with hasNext function.
Downloads
5
Maintainers
Readme
iterator-has-next
Simple helper that wraps standard AsyncIterableIterator and provides .hasNext()
method.
Example code bellow or you can try it on repl.it.
async function usage () {
// Create dummy iterator with 3 elemnts
const iterator = createIterator(3)
// Extend iterator to get one with .hasNext() method
const extendedIterator = await extendIterator(iterator)
console.log(`Example #1 how utilize new method`)
for await (let i of extendedIterator) {
console.log(`${i} | ${extendedIterator.hasNext()}`)
}
console.log(`Example #2 of how to use .hasNext()`)
const it = await extendIterator(createIterator(3))
while (it.hasNext()) {
const { value } = await it.next()
console.log(`${value} | ${it.hasNext()}`)
}
}