{"_id":"@harperfast/extended-iterable","_rev":"4300708","name":"@harperfast/extended-iterable","description":"Extended iterable class, providing lazy array-like methods with automatic async and return/throw forwarding","dist-tags":{"latest":"1.0.3"},"maintainers":[{"name":"cb1kenobi","email":"chris@cb1inc.com"},{"name":"dawsontoth","email":""},{"name":"ethan_arrowood","email":"ethan.arrowood@gmail.com"},{"name":"harperdb_team","email":""},{"name":"heskew","email":"heskew@gmail.com"},{"name":"kriszyp","email":"kriszyp@gmail.com"}],"time":{"modified":"2026-04-07T21:15:16.000Z","created":"2025-12-18T14:37:26.712Z","1.0.3":"2026-01-23T21:05:38.304Z","1.0.2":"2026-01-23T20:59:31.101Z","1.0.1":"2025-12-18T14:37:26.712Z"},"users":{},"author":{"name":"Harper"},"repository":{"type":"git","url":"git+ssh://git@github.com/harperdb/extended-iterable.git"},"versions":{"1.0.3":{"name":"@harperfast/extended-iterable","author":{"name":"Harper"},"version":"1.0.3","description":"Extended iterable class, providing lazy array-like methods with automatic async and return/throw forwarding","license":"Apache-2.0","repository":{"type":"git","url":"git+ssh://git@github.com/harperdb/extended-iterable.git"},"keywords":["iterable","lazy"],"scripts":{"build":"rollup -c"},"type":"module","module":"./index.js","exports":{".":{"import":"./index.js","require":"./dist/index.cjs"}},"types":"./index.d.ts","devDependencies":{"rollup":"^4.53.3"},"_id":"@harperfast/extended-iterable@1.0.3","gitHead":"377ea442f5a056d9b3d7008630ea322c8f8ac4cc","bugs":{"url":"https://github.com/harperdb/extended-iterable/issues"},"homepage":"https://github.com/harperdb/extended-iterable#readme","_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"shasum":"471489c5058331017e821bf6c33de70fc2c073ee","size":12707,"noattachment":false,"key":"/@harperfast/extended-iterable/-/@harperfast/extended-iterable-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/@harperfast/extended-iterable/download/@harperfast/extended-iterable-1.0.3.tgz"},"_npmUser":{"name":"kriszyp","email":"kriszyp@gmail.com"},"directories":{},"maintainers":[{"name":"cb1kenobi","email":"chris@cb1inc.com"},{"name":"dawsontoth","email":""},{"name":"ethan_arrowood","email":"ethan.arrowood@gmail.com"},{"name":"harperdb_team","email":""},{"name":"heskew","email":"heskew@gmail.com"},{"name":"kriszyp","email":"kriszyp@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/extended-iterable_1.0.3_1769202338164_0.15188701881780609"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-01-23T21:05:38.304Z","publish_time":1769202338304,"_source_registry_name":"default","_cnpm_publish_time":1769202338304},"1.0.2":{"name":"@harperfast/extended-iterable","author":{"name":"Harper"},"version":"1.0.2","description":"Extended iterable class, providing lazy array-like methods with automatic async and return/throw forwarding","license":"Apache-2.0","repository":{"type":"git","url":"git+ssh://git@github.com/harperdb/extended-iterable.git"},"keywords":["iterable","lazy"],"scripts":{"build":"rollup -c"},"type":"module","module":"./index.js","exports":{".":{"import":"./index.js","require":"./dist/index.cjs"}},"types":"./index.d.ts","devDependencies":{"rollup":"^4.53.3"},"_id":"@harperfast/extended-iterable@1.0.2","gitHead":"a623aa98f428179fe1c5cae55afb303b46eb8dc6","bugs":{"url":"https://github.com/harperdb/extended-iterable/issues"},"homepage":"https://github.com/harperdb/extended-iterable#readme","_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"shasum":"0ad84f53adb591799e5576f08f829fa3eb102e3c","size":8557,"noattachment":false,"key":"/@harperfast/extended-iterable/-/@harperfast/extended-iterable-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/@harperfast/extended-iterable/download/@harperfast/extended-iterable-1.0.2.tgz"},"_npmUser":{"name":"kriszyp","email":"kriszyp@gmail.com"},"directories":{},"maintainers":[{"name":"cb1kenobi","email":"chris@cb1inc.com"},{"name":"dawsontoth","email":""},{"name":"ethan_arrowood","email":"ethan.arrowood@gmail.com"},{"name":"harperdb_team","email":""},{"name":"heskew","email":"heskew@gmail.com"},{"name":"kriszyp","email":"kriszyp@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/extended-iterable_1.0.2_1769201970947_0.4563995270988004"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-01-23T20:59:31.101Z","publish_time":1769201971101,"_source_registry_name":"default","_cnpm_publish_time":1769201971101},"1.0.1":{"name":"@harperfast/extended-iterable","author":{"name":"Harper"},"version":"1.0.1","description":"Extended iterable class, providing lazy array-like methods with automatic async and return/throw forwarding","license":"Apache-2.0","repository":{"type":"git","url":"git+ssh://git@github.com/harperdb/extended-iterable.git"},"keywords":["iterable","lazy"],"scripts":{"build":"rollup -c"},"type":"module","module":"./index.js","exports":{".":{"import":"./index.js","require":"./dist/index.cjs"}},"types":"./index.d.ts","devDependencies":{"rollup":"^4.53.3"},"_id":"@harperfast/extended-iterable@1.0.1","gitHead":"71bd4a4769a73a33a696500b638a4378d068008e","bugs":{"url":"https://github.com/harperdb/extended-iterable/issues"},"homepage":"https://github.com/harperdb/extended-iterable#readme","_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"shasum":"29f4a46da06400ea294646525326e46c81dee3e8","size":8557,"noattachment":false,"key":"/@harperfast/extended-iterable/-/@harperfast/extended-iterable-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@harperfast/extended-iterable/download/@harperfast/extended-iterable-1.0.1.tgz"},"_npmUser":{"name":"kriszyp","email":"kriszyp@gmail.com"},"directories":{},"maintainers":[{"name":"cb1kenobi","email":"chris@cb1inc.com"},{"name":"dawsontoth","email":""},{"name":"ethan_arrowood","email":"ethan.arrowood@gmail.com"},{"name":"harperdb_team","email":""},{"name":"heskew","email":"heskew@gmail.com"},{"name":"kriszyp","email":"kriszyp@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/extended-iterable_1.0.1_1766068646563_0.5746237493440709"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-12-18T14:37:26.712Z","publish_time":1766068646712,"_source_registry_name":"default","_cnpm_publish_time":1766068646712}},"readme":"[![license](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)\n[![npm version](https://img.shields.io/npm/v/extended-iterable.svg?style=flat-square)](https://www.npmjs.org/package/extended-iterable)\n[![npm downloads](https://img.shields.io/npm/dw/extended-iterable)](https://www.npmjs.org/package/extended-iterable)\n\nThe extended-iterable package provides a class that implements the Iterable/Iterator protocol and provides array-like methods\nwith lazy evaluation, similar to [iterators helpers](https://github.com/tc39/proposal-iterator-helpers). However,\nextended-iterable provides additional methods, the ability to handle both sync and async iteration, automatic handling of\nasynchronous callbacks, and return/throw forwarding which can be critical for proper cleanup when used with\ndatabase transactions.\n\nThe package exports a single `ExtendedIterable` class, which can be constructed with a basic iterable or can be constructed\nwith no arguments and assigned (or overridden with) an `iterate` method that returns an iterator.\n\nFor example, we can create an `ExtendedIterable`:\n```javascript\nimport { ExtendedIterable } from '@harperdb/extended-iterable';\n\nfunction performQuery() {\n\tlet results = new ExtendedIterable();\n\tresults.iterate = function() {\n\t\tlet txn = startTxn(); // we can start a transaction in some database, and be notified of when the iterable is completed below\n\t\tlet cursor = txn.doQuery();\n\t\treturn {\n\t\t\t// implement an iterator\n\t\t\tnext() {\n\t\t\t\t// iterate through a query or table\n\t\t\t\tlet entry = cursor.getNext();\n\t\t\t\tif (entry)\n\t\t\t\t\treturn { value: entry };\n\t\t\t\telse\n\t\t\t\t\treturn { done: true };\n            },\n\t\t\treturn () { // called when the iterator is done\n\t\t\t\ttxn.commit();\n            },\n\t\t\tthrow () {\n\t\t\t\ttxn.abort();\n            }\n        }\n    };\n\treturn results;\n}\n```\n\n\nThe returned `ExtendedIterable` is fully iterable: \n\n```js\nlet extendedIterable = performQuery();\nfor (let value of extendedIterable) {\n\t// for each value\n}\n```\n\nOr we can use the provided iterative methods on the returned results:\n\n```js\nextendedIterable\n\t.filter((value) => test(value))\n\t.forEach((value) => {\n\t\t// for each value that matched the filter\n\t})\n```\n\nNote that `map` and `filter` are also lazy, they will only be executed once their returned iterable is iterated or `forEach` is called on it. The `map` and `filter` functions also support async/promise-based functions, and you can create an async iterable if the callback functions execute asynchronously (return a promise).\n\nWe can also query with offset to skip a certain number of entries, and limit the number of entries to iterate through:\n\n```js\nlet sliced = extendedIterable.slice(10, 20); // skip first 10 and get next 10\n```\n\nIf you want to get a true array from the results, the `asArray` property will return the results as an array.\n\n### Catching Errors in iteration\nWith an array, `map` and `filter` callbacks are immediately executed, but wit iterators, they are executed during iteration, so if an error occurs during iteration, the error will be thrown when the iteration is attempted. It is also critical that when an iteration is finished, the cursor is closed, so by default, if an error occurs during iteration, the cursor will immediately be closed. However, if you want to catch errors that occur in `map` (and `flatMap`) callbacks during iteration, you can use the `mapError` method to catch errors that occur during iteration, and allow iteration to continue (without closing the cursor). For example:\n\n```js \nlet mapped = extendedIterable.map(({ key, value }) => {\n\treturn thisMightThrowError(value);\n}).mapError((error) => {\n    // rather than letting the error terminate the iteration, we can catch it here and return a value to continue iterating:\n    return 'error occurred';\n})\nfor (let entry of mapped) {\n...\n}\n```\nA `mapError` callback can return a value to continue iterating, or throw an error to terminate the iteration.\n\n## License\n\nThis library is licensed under the terms of the MIT license.\n\n## Related Projects\n","_attachments":{},"homepage":"https://github.com/harperdb/extended-iterable#readme","bugs":{"url":"https://github.com/harperdb/extended-iterable/issues"},"license":"Apache-2.0"}