{"id":27373976,"url":"https://github.com/arccoza/iterly","last_synced_at":"2025-04-13T11:36:07.098Z","repository":{"id":34238194,"uuid":"171870558","full_name":"arccoza/iterly","owner":"arccoza","description":"Composable iterator and async iterator tools, supporting old platforms without yield or async/await","archived":false,"fork":false,"pushed_at":"2023-01-04T21:38:46.000Z","size":617,"stargazers_count":1,"open_issues_count":18,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T01:50:39.379Z","etag":null,"topics":["async","async-iterable","async-iterator","asynciterator","composable","iterable","iterator","no-dependencies","zero-dependencies"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arccoza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-21T12:47:20.000Z","updated_at":"2019-10-29T09:11:25.000Z","dependencies_parsed_at":"2023-01-15T05:30:50.074Z","dependency_job_id":null,"html_url":"https://github.com/arccoza/iterly","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arccoza%2Fiterly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arccoza%2Fiterly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arccoza%2Fiterly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arccoza%2Fiterly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arccoza","download_url":"https://codeload.github.com/arccoza/iterly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248438510,"owners_count":21103409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-iterable","async-iterator","asynciterator","composable","iterable","iterator","no-dependencies","zero-dependencies"],"created_at":"2025-04-13T11:36:06.537Z","updated_at":"2025-04-13T11:36:07.088Z","avatar_url":"https://github.com/arccoza.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Description\n\nAn iterator / async-iterator library with support for old platforms that don't have iterables or async-iterables.\nIterly provides several useful functions for composing, manipulating and iterating through iterables,\nasync-iterables, arrays, streams, and array-like objects such as nodejs Buffer.\n\nEven though iterly doesn't use async functions or generators, and should work on browsers as far back as ie10,\nyou will still need to pass your code through Babel or similar to transpile modern syntax used in this library,\nsuch as destructuring.\n\n# Install\n\n`yarn add iterly` or `npm install iterly`\n\n# API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### Table of Contents\n\n-   Iteration helpers\n    -   [each](#each)\n    -   [iter](#iter)\n    -   [iterArray](#iterarray)\n    -   [iterObject](#iterobject)\n    -   [iterFn](#iterfn)\n-   Function composition\n    -   [compose](#compose)\n    -   [curry](#curry)\n-   Sync operators\n    -   [map](#map)\n    -   [reduce](#reduce)\n    -   [filter](#filter)\n-   Async operators\n    -   [amap](#amap)\n    -   [areduce](#areduce)\n    -   [afilter](#afilter)\n-   Sync / Async operators\n    -   [enumerate](#enumerate)\n-   [Range](#range)\n-   [range](#range-1)\n\n## each\n\nLoops over any iterable, async-iterable, iterator, async-iterator or array-like,\ncalling fn for each item. If looping over an async-iterable / async-iterator\na promise will be returned by each with the value of the final return from fn.\n\n### Parameters\n\n-   `x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The number of async items to run in parallel, has no effect on sync iterables. (optional, default `1`)\n-   `fn` **(function (value) | function (value, done))** The fn to call for each item. The function will be called\n    for every value in the iterable / async-iterable. If the function has a second param (done) then\n    the loop function will be called when the iterable / async-iterable is done, with a done value of true.\n    If no second param (done) is provided then the loop function will only be called with the values from\n    the iterable / async-iterable.\n-   `it` **(iterable | asyncIterable)** The iterable, async-iterable, iterator, async-iterator or array-like\n    to loop over.\n\n### Examples\n\n```javascript\neach((value) =\u003e console.log(value), [1, 2, 3, 4])\n// Will print:\n// 1\n// 2\n// 3\n// 4\n```\n\nReturns **([Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) \\| [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** Returns a Promise that resolves to the last value returned by fn if looping\nover an async-iterable. If looping over an iterable returns undefined.\n\n## iter\n\nGets an iterator / async-iterator for any iterable, async-iterable, array-like, or function with a sentinel.\n\n### Parameters\n\n-   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The possible iterable to create an iterator for.\n-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**  (optional, default `{}`)\n    -   `options.sentinel`  Any distinct value to use as a stop indicator when creating an iterator from a function,\n        see iterFn.\n    -   `options.isAsync` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true and obj is a function, an async-iterator will be returned. (optional, default `false`)\n\nReturns **(@@iterator | @@asyncIterator | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** Returns an iterator, async-iterator, or undefined if obj is not iterable.\n\n## iterArray\n\nGets an iterator for any array-like; that is anything with a length property that\ncan be indexed with array[index] notation.\n\n### Parameters\n\n-   `a` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | arrayLike)** The array-like to create an iterator from.\n-   `chunkSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** If set larger than zero, will break the array up\n    into chunks of length chunkSize. (optional, default `0`)\n\n### Examples\n\n```javascript\nvar it = iterArray([1, 2, 3, 4])\n// Will give you an iterator with the values: 1, 2, 3, 4\nvar it = iterArray([1, 2, 3, 4], 2)\n// Will give you an iterator with the values: [1, 2], [3, 4]\n```\n\nReturns **@@iterator** Returns an iterator with the values from the array-like.\n\n## iterObject\n\nGets an iterator of [key, value] pairs for any javascript object.\n\n### Parameters\n\n-   `o` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The object to create an iterator from. Only iterates over an objects own-properties.\n\n### Examples\n\n```javascript\nvar it = iterObject({a: 1, b: 2, c: 3})\n// Will give you an iterator with the values: [a, 1], [b, 2], [c, 3]\n```\n\nReturns **@@iterator** Returns an iterator with the [key, value] pairs from the object.\n\n## iterFn\n\nTurns a function into an iterator.\n\n### Parameters\n\n-   `fn` **function ({i, sentinel})** The iterator will return whatever this function returns,\n    until it returns the sentinel value, then it will stop. The function is given an object with\n    an index i and the sentinel value, you can add any other state you want to keep between iterations\n    to this object if you like.\n-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** This options object must contain the sentinel property, the sentinel\n    is returned by fn to signal the end of iteration.\n    -   `options.sentinel`  Any distinct value to use as an indicator that the iterator function is done.\n    -   `options.isAsync` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true an async-iterator will be returned. (optional, default `false`)\n\n### Examples\n\n```javascript\nvar it = iterFn(({i, sentinel}) =\u003e i \u003e= 4 ? sentinel : i * 2, {sentinel: {}})\n// Will give you an iterator with the values: 0, 2, 4, 6\n```\n\nReturns **(@@iterator | @@asyncIterator)** Returns an iterator or async-iterator with the values returned by fn.\n\n## compose\n\nPerhaps the most useful function here; allows you to compose (combine)\nother functions into one new function that takes one argument of\nan iterable, async-iterable, iterator, or async-iterator.\n\n### Parameters\n\n-   `fns` **...[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Any number of functions to combine.\n\n### Examples\n\n```javascript\nvar urlPrefix = 'http://some.resource.com/'\nvar files = ['file.txt', 'file2.txt', 'file3.txt', 'file4.txt']\n\nvar getShortTexts = compose(\n  filter.curry(file =\u003e file != 'file3.txt'), // Removes file3.txt\n  map.curry(file =\u003e urlPrefix + file), // Adds the url prefix to the file names, creating the file url\n  amap.curry(url =\u003e fetch(url).then(res =\u003e res.text())), // Fetches the files from the web\n  afilter.curry(txt =\u003e txt.length \u003c= 140), // Removes files longer than 140 characters\n)\n\neach(txt =\u003e console.log(txt), getShortTexts([files]))\n// Will print out the contents of the files with 140 or fewer chracters, skipping file3.txt.\n```\n\nReturns **function (it: anyIterableOrAsyncIterable)** The composed function.\n\n## curry\n\nReturns a curried version of the provided function.\n\n### Parameters\n\n-   `fn` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to curry.\n-   `args` **...any?** Any arguments to bind.\n\nReturns **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Returns the curried function.\n\n## map\n\nA function that maps iterator or iterable values over a function.\n\n### Parameters\n\n-   `fn` **function (value: any, index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** The function to modify each value in the iterator.\n-   `it` **@@iterator** The iterator or iterable to map over.\n\n### Examples\n\n```javascript\nvar it = map(v =\u003e 2 * v, [1, 2, 3, 4])\n// Will give you an iterator with the values: 2, 4, 6, 8\n```\n\nReturns **@@iterator** Returns an iterator with values that will be updated by fn.\n\n### curry\n\nAllows you to curry the arguments, most useful when used with compose.\n\n#### Parameters\n\n-   `args` **...any** The arguments to bind.\n\n#### Examples\n\n```javascript\nvar curried = map.curry(v =\u003e 2 * v)\nvar it = [1, 2, 3, 4]\nit = curried(it)\n// Will give you an iterator with the values: 2, 4, 6, 8\n```\n\nReturns **curriedFunction** The curried version of the original function, with bindable args.\n\n## reduce\n\nA function that reduces all the items in an iterator or iterable to one value.\n\n### Parameters\n\n-   `fn` **function (accumulator: any, value: any, index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** The reducer function continually updates\n    the accumulator, until the iterator ends, then the accumulated value is returned.\n-   `acc`  The accumulator's initial value, each item in the iterator or iterable will be added to this by fn.\n-   `it` **@@iterator** The iterator or iterable to reduce.\n\n### Examples\n\n```javascript\nvar it = reduce((acc, v) =\u003e acc += v, 0, [1, 2, 3, 4])\n// Will give you an iterator with the value: 10\nvar it = reduce((acc, v, i) =\u003e (acc[i] = v, acc), [], [1, 2, 3, 4])\n// Will give you an iterator with a single item, which will be an array: [1, 2, 3, 4]\n```\n\nReturns **@@iterator** Returns an iterator with only one value.\n\n### curry\n\nAllows you to curry the arguments, most useful when used with compose.\n\n#### Parameters\n\n-   `args` **...any** The arguments to bind.\n\n#### Examples\n\n```javascript\nvar curried = reduce.curry((acc, val) =\u003e acc + val)\nvar it = [1, 2, 3, 4]\nit = curried(it)\n// Will give you an iterator with the value: 10\n```\n\nReturns **curriedFunction** The curried version of the original function, with bindable args.\n\n## filter\n\nA function that keeps values in an iterator or iterable only if fn returns true.\n\n### Parameters\n\n-   `fn` **function (value: any, index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** The test function to filter items,\n    return true to keep the item, false to remove it.\n-   `it` **@@iterator** The iterator or iterable to filter.\n\n### Examples\n\n```javascript\nvar it = filter(v =\u003e v != 2, [1, 2, 3, 4])\n// Will give you an iterator with the values: 1, 3, 4\n```\n\nReturns **@@iterator** Returns an iterator with only the values that passed the test fn.\n\n### curry\n\nAllows you to curry the arguments, most useful when used with compose.\n\n#### Parameters\n\n-   `args` **...any** The arguments to bind.\n\n#### Examples\n\n```javascript\nvar curried = filter.curry(v =\u003e v != 2)\nvar it = [1, 2, 3, 4]\nit = curried(it)\n// Will give you an iterator with the values: 1, 3, 4\n```\n\nReturns **curriedFunction** The curried version of the original function, with bindable args.\n\n## amap\n\nA function that maps iterator, iterable, async-iterator or async-iterable values over a function.\n\n### Parameters\n\n-   `fn` **function (value: any, index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** The function to modify each value in the iterator.\n-   `it` **(@@iterator | @@asyncIterator)** The iterator, iterable, async-iterator or async-iterable to map over.\n\n### Examples\n\n```javascript\nvar it = amap(v =\u003e 2 * v, [1, 2, 3, 4])\n// Will give you an async-iterator with the promised values: 2, 4, 6, 8\n\nvar urls = ['http://some.resource.com/file.txt', 'http://some.resource.com/file2.txt']\nvar it = amap(url =\u003e fetch(url).then(res =\u003e res.text()), urls)\nit = amap(txt =\u003e txt.slice(0, 140), it)\neach(txt =\u003e console.log(txt), it)\n// Will print the first 140 characters of text for each file referenced by the urls\n```\n\nReturns **@@asyncIterator** Returns an async-iterator with values returned by fn.\n\n### curry\n\nAllows you to curry the arguments, most useful when used with compose.\n\n#### Parameters\n\n-   `args` **...any** The arguments to bind.\n\n#### Examples\n\n```javascript\nvar curried = amap.curry(v =\u003e 2 * v)\nvar it = [1, 2, 3, 4]\nit = curried(it)\n// Will give you an async-iterator with the promised values: 2, 4, 6, 8\n```\n\nReturns **curriedFunction** The curried version of the original function, with bindable args.\n\n## areduce\n\nA function that reduces an iterator, iterable, async-iterator or async-iterable to one promised value.\n\n### Parameters\n\n-   `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** If a value greater than 0 is provided, then areduce will create multiple,\n    grouped reductions, each made of `n` items, like a scan fn. (optional, default `0`)\n-   `fn` **function (accumulator: any, value: any, index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** The reducer function continually updates\n    the accumulator, until the iterator / async-iterator ends, then the accumulated value is returned.\n-   `acc`  The accumulator's initial value, each item in the iterator or iterable will be added to this by fn.\n-   `it` **(@@iterator | @@asyncIterator)** The iterator, iterable, async-iterator or async-iterable to reduce.\n\n### Examples\n\n```javascript\nvar it = areduce((acc, v) =\u003e acc += v, 0, [1, 2, 3, 4])\n// Will give you an async-iterator with the promised value: 10\n\nvar urls = ['http://some.resource.com/file.txt', 'http://some.resource.com/file2.txt']\nvar it = amap(url =\u003e fetch(url).then(res =\u003e res.text()), urls)\nit = areduce((acc, txt) =\u003e acc + txt.slice(0, 140), '', it)\neach(txt =\u003e console.log(txt), it)\n// Will print the combined 280 characters of text from each file referenced by the urls\n```\n\nReturns **@@asyncIterator** Returns an async-iterator with only one promised value.\n\n### curry\n\nAllows you to curry the arguments, most useful when used with compose.\n\n#### Parameters\n\n-   `args` **...any** The arguments to bind.\n\n#### Examples\n\n```javascript\nvar curried = areduce.curry((acc, val) =\u003e acc + val)\nvar it = [1, 2, 3, 4]\nit = curried(it)\n// Will give you an async-iterator with the promised value: 10\n```\n\nReturns **curriedFunction** The curried version of the original function, with bindable args.\n\n## afilter\n\nA function that keeps values in an iterator, iterable, async-iterator or async-iterable,\nonly if fn returns true.\n\n### Parameters\n\n-   `fn` **function (value: any, index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** The test function to filter items,\n    return true to keep the item, false to remove it.\n-   `it` **(@@iterator | @@asyncIterator)** The iterator, iterable, async-iterator or async-iterable to filter.\n\n### Examples\n\n```javascript\nvar it = afilter(v =\u003e v != 2, [1, 2, 3, 4])\n// Will give you an async-iterator with the promised values: 1, 3, 4\n\nvar urls = ['http://some.resource.com/file.txt', 'http://some.resource.com/file2.txt']\nvar it = amap(url =\u003e fetch(url).then(res =\u003e res.text()), urls)\nit = afilter(txt =\u003e txt.length \u003c 140, it)\neach(txt =\u003e console.log(txt), it)\n// Will only print the text of the files, referenced by the urls, with fewer than 140 characters\n```\n\nReturns **@@asyncIterator** Returns an async-iterator with the values that passed the test fn.\n\n### curry\n\nAllows you to curry the arguments, most useful when used with compose.\n\n#### Parameters\n\n-   `args` **...any** The arguments to bind.\n\n#### Examples\n\n```javascript\nvar curried = afilter.curry(v =\u003e v != 2)\nvar it = [1, 2, 3, 4]\nit = curried(it)\n// Will give you an async-iterator with the promised values: 1, 3, 4\n```\n\nReturns **curriedFunction** The curried version of the original function, with bindable args.\n\n## enumerate\n\nEnumerate takes an iterable, async-iterable, iterator, or async-iterator\nand returns the same with its values updated with an [index, value] pair,\nstarting at 0 or at the optional start arg.\n\n### Parameters\n\n-   `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The optional index start. (optional, default `0`)\n-   `it` **(iterable | asyncIterable)** The iterable or async-iterable to return.\n\n### Examples\n\n```javascript\nvar arr = ['a', 'b', 'c', 'd']\nvar it = enumerate(arr)\n// Will give you an iterator with the values: [0, 'a'], [1, 'b'], [2, 'c'], [3, 'd']\n```\n\nReturns **(iterator | asyncIterator)** Returns an iterator or async-iterator with\nthe [index, value] pair items.\n\n## Range\n\nCreates a Range object that can be iterated over.\n\n### Parameters\n\n-   `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The start of the range (inclusive). (optional, default `0`)\n-   `stop` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The end of the range (exclusive).\n-   `step` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The stride of the range. (optional, default `1`)\n\nReturns **[Range](#range)** \n\n### ITERATOR\n\nCreates an iterator of all the values in the range.\n\nReturns **Iterator** \n\n### values\n\nCreates an iterator of all the values in the range.\n\nReturns **Iterator** \n\n### entries\n\nCreates an iterator of all the entries in the range.\n\nReturns **Iterator** Returns value pairs [value, value], like Set.\n\n### get\n\nGet an item from a range by index.\n\n#### Parameters\n\n-   `idx` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the value in the range.\n\nReturns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Returns the value at the index, or undefined.\n\n### has\n\nCheck if a value exists in a range.\n\n#### Parameters\n\n-   `val` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The value to look for.\n\nReturns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true if the value exists.\n\n### indexOf\n\nFind the index of a value in the range.\n\n#### Parameters\n\n-   `val` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The value to look for.\n\nReturns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Returns the index if the value exists, -1 otherwise.\n\n### new\n\nAn alternative, static method, Range constructor.\n\n#### Parameters\n\n-   `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The start of the range (inclusive). (optional, default `0`)\n-   `stop` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The end of the range (exclusive).\n-   `step` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The stride of the range. (optional, default `1`)\n\nReturns **[Range](#range)** \n\n## range\n\nAn alternative, functional, Range constructor.\n\n### Parameters\n\n-   `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The start of the range (inclusive). (optional, default `0`)\n-   `stop` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The end of the range (exclusive).\n-   `step` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The stride of the range. (optional, default `1`)\n\nReturns **[Range](#range)** \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farccoza%2Fiterly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farccoza%2Fiterly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farccoza%2Fiterly/lists"}