{"id":28365332,"url":"https://github.com/toolbuilder/iterablefu","last_synced_at":"2025-08-01T14:02:41.721Z","repository":{"id":57278478,"uuid":"199493943","full_name":"toolbuilder/iterablefu","owner":"toolbuilder","description":"Small (1.2kb gz), set of functions like range, map, reduce, filter, zip, for iterable objects.","archived":false,"fork":false,"pushed_at":"2024-11-08T17:14:23.000Z","size":968,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T23:45:02.856Z","etag":null,"topics":["chainable","es6","esm","functional","generator","iterable","iterator"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toolbuilder.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-29T17:00:46.000Z","updated_at":"2025-04-03T21:33:16.000Z","dependencies_parsed_at":"2024-11-08T18:21:28.533Z","dependency_job_id":"5ef230d1-0ff9-47f2-8f9f-665102e5a867","html_url":"https://github.com/toolbuilder/iterablefu","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/toolbuilder/iterablefu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolbuilder%2Fiterablefu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolbuilder%2Fiterablefu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolbuilder%2Fiterablefu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolbuilder%2Fiterablefu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toolbuilder","download_url":"https://codeload.github.com/toolbuilder/iterablefu/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolbuilder%2Fiterablefu/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268240279,"owners_count":24218355,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["chainable","es6","esm","functional","generator","iterable","iterator"],"created_at":"2025-05-28T21:10:38.855Z","updated_at":"2025-08-01T14:02:41.696Z","avatar_url":"https://github.com/toolbuilder.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IterableFu\n\n`IterableFu` is a small (1.2kb minimized and gzipped) library of functions like range, map, reduce, filter, zip, for iterable objects.\n\n`IterableFu` has a chainable class to make it easy to chain iterable transforms. There is a chainable class factory\n[makeChainableIterable](docs/makechainable.md), so you easily can add methods, or reduce bundle size.\n\n## Features\n\n* Chainable: `chainable([0, 1, 2]).map(x =\u003e 2*x).toArray()`.\n* Works with your generators (and iterables): `chainable(yourGenerator()).mapWith(yourTransformGenerator)`.\n* Customizable [makeChainableIterable](docs/makechainable.md), to add methods or reduce bundle sizes.\n* Functional API takes data last, so you can curry, pipe and compose with your functional library.\n* Exports both CommonJS and ES modules - dual package.\n\nIf you want asynchronous iterables along with task pool, event queue, pub/sub, merge, chunk, throttle, and the like, checkout [await-for-it](https://github.com/toolbuilder/await-for-it#readme).\n\n## Table of Contents\n\n\u003c!-- !toc (minlevel=2 omit=\"Features;Table of Contents\") --\u003e\n\n* [Installation](#installation)\n* [Getting Started](#getting-started)\n* [API](#api)\n* [Examples](#examples)\n  * [Basics](#basics)\n  * [One Time Use](#one-time-use)\n  * [Iterablefu and Your Generators](#iterablefu-and-your-generators)\n* [Smaller Bundles](#smaller-bundles)\n* [Customization](#customization)\n* [Alternatives](#alternatives)\n* [Contributing](#contributing)\n* [Issues](#issues)\n* [License](#license)\n\n\u003c!-- toc! --\u003e\n\n## Installation\n\n```bash\nnpm install --save iterablefu\n```\n\n## Getting Started\n\nIf you want the chainable API, use this import.\n\n```javascript\nimport { chainable } from 'iterablefu'\n```\n\n```javascript\nimport { chainable } from 'iterablefu'\n\nconst iterable = chainable([1, 2, 3, 4, 5, 6]) // \u003c-- throw any synchronous iterable in here\n  .filter(x =\u003e x % 2 === 0) // filters out odd numbers\n  .map(x =\u003e 2 * x)\n\nconsole.log(Array.from(iterable)) // prints [4, 8, 12]\n```\n\nThe most used methods are probably: `zip`, `zipAll`, `filter`, `flatten`, `map`, and `reduce`.\nThe documentation has an example for each method:\n\n* [chainable](docs/chainable.md)- Is a factory that starts the chain and produces a `ChainableIterable`\n* [ChainableIterable](docs/ChainableIterable.md) - For all the transforms and reducer methods\n\nIf you want the functional API, use this import.\n\n```javascript\nimport { generators, transforms, reducers } from 'iterablefu'\n```\n\nYou may also specify the modules directly to reduce bundle sizes. See more in the\n[Smaller Bundles](#smaller-bundles) section.\n\n## API\n\n* Chainable API\n  * [Chainable factory](docs/chainable.md), factory functions that produce `ChainableIterable` instances\n  * [ChainableIterable](docs/ChainableIterable.md), chainable iterable generators, transforms, and reducers\n  * [Custom chainables](docs/makechainable.md), create custom chainable iterables\n* Functional API\n  * [Generators](docs/generators.md), generator functions to create iterable sequences\n  * [Transforms](docs/transforms.md), functions to convert an iterable into another iterable (e.g. map, filter)\n  * [Reducers](docs/reducers.md), functions to convert an iterable into a value\n\n## Examples\n\n### Basics\n\n`IterableFu` provides three basic categories of functions:\n\n* **Generators** - create an iterable sequence\n* **Transforms** - convert one iterable sequence into another\n* **Reducers** - convert an iterable sequence into a value\n\nHere's a quick example showing `range` (a generator), `map` (a transform), and `reduce` (a reducer).\n\n```javascript\nimport { chainable } from 'iterablefu'\nconst answer =\n  chainable\n    .range(5) // generates 0, 1, 2, 3, 4\n    .map(x =\u003e 2 * x) // maps to 0, 2, 4, 6, 8\n    .reduce((a, x) =\u003e a + x, 0) // 0 + 2 + 4 + 6 + 8 = 20\nconsole.log(answer) // prints 20\n```\n\nSome generators can convert Arrays or any other iterable into chainable iterables.\n\n```javascript\nconst d = chainable([1, 2, 3]) // makes a chainable version of [1, 2, 3]\nconst e = chainable.concatenate([0, 1, 2], [3, 4]) // becomes [0, 1, 2, 3, 4]\nconst f = chainable.zip([1, 2, 3], ['a', 'b', 'c']) // becomes [[1, 'a'], [2, 'b'], [3, 'c']]\n```\n\nThere are several ways to convert back to Arrays.\n\n```javascript\nconst a = Array.from(chainable.range(5)) // a has the value [0, 1, 2, 3, 4, 5]\nconst b = [...chainable.range(3)] // b has the value [0, 1, 2]\nconst c = chainable.range(2, 5).toArray() // c has the value [2, 3, 4, 5, 6]\n```\n\n### One Time Use\n\nExcept for one method, `repeatIterable`, `IterableFu` only supports one-time iteration. This is because\niterators cannot be reused once done.\n\nAn iterable class like Array, can be iterated more than once because it produces a new iterator for each iteration.\n\n```javascript\n// IterableFu produces one-time use sequences\nconst a = chainable.range(5)\nconsole.log([...a]) // print [0, 1, 2, 3, 4], iterator is now done\nconsole.log([...a]) // prints [] because the iterator was done before the call\n```\n\nTo reuse an `IterableFu` chain, wrap it in a function so that a new Generator object is returned each time it is called.\n\n```javascript\nconst fn = () =\u003e chainable.range(5)\n// Note the function calls below...\nconsole.log([...fn()]) // prints [0, 1, 2, 3, 4]\nconsole.log([...fn()]) // prints [0, 1, 2, 3, 4] because a new iterator was used\n```\n\n### Iterablefu and Your Generators\n\nTo use a generator function that creates a sequence, use [chainable](docs/chainable.md) as a function.\n\n```javascript\n// A simple generator function\nconst fn = function * (length) {\n  for (let i = 0; i \u003c length; i++) {\n    yield i\n  }\n}\n// be sure to call the generator, don't just pass the function\nconst a = chainable(fn(3))\nconsole.log([...a]) // prints [0, 1, 2]\n```\n\nTo use a generator that transforms a sequence, use `mapWith`.\n\n```javascript\n// An example generator that transforms another sequence.\nconst fn = function * (n, iterable) {\n  for (let x of iterable) {\n    yield n * x\n  }\n}\nconst input = [0, 1, 2, 3, 4]\n// mapWith only accepts generator functions that have one parameter: iterable.\n// If your generator takes additional parameters beyond iterable, you need\n// to wrap it with another function that takes only one parameter. Like this:\nconst wrapper = (iterable) =\u003e fn(3, iterable)\nconst a = chainable(input).mapWith(wrapper).toArray()\nconsole.log(a) // prints [0, 3, 6, 9, 12]\n```\n\n## Smaller Bundles\n\nYou can potentially reduce bundle size by importing the generators and function you want to use directly.\n\n```javascript\nimport { zip, zipAll } from 'iterablefu/src/generators.js'\nimport { filter, flatten, map } from 'iterablefu/src/transfroms.js'\nimport { reduce } from 'iterablefu/src/reducers.js'\n```\n\nIf you want a reduced size chainable object, use [makeChainableIterable](docs/makechainable.md) with the\ndirectly imported functions. Customization is covered more completely in the `makeChainableIterable` docs.\n\n```javascript\n// using the imports from above\nimport { makeChainableIterable } from 'iterablefu/src/makechainable.js'\nconst generators = { zip, zipAll }\nconst transforms = { filter, flatten, map }\nconst reducers = { reduce }\nconst chainable = makeChainableIterable(generators, transforms, reducers)\n```\n\n## Customization\n\nCustomization is covered  in the [makeChainableIterable](docs/makechainable.md) documentation.\n\n## Alternatives\n\nThere are lots of alternatives:\n\n* [wu](https://github.com/fitzgen/wu.js) - has many more methods than `IterableFu`. Does not use ES6 modules.\n* [itiri](https://github.com/labs42io/itiriri) - many functions that force conversion to array. Typescript.\n* [lazy.js](https://github.com/dtao/lazy.js/) - more methods, does not use generators\n* [linq.js](https://github.com/mihaifm/linq) - LINQ (a .NET library) for JavaScript\n* [GenSequence](https://github.com/Jason3S/GenSequence) - similar to `IterableFu`. Typescript.\n\n... and many more.\n\n## Contributing\n\nContributions are welcome. Please create a pull request.\n\nI use [pnpm](https://pnpm.js.org/) instead of npm.\n\nAutomated browser tests use electron. Automated package tests build a `*.tgz` package and run tweaked unit tests in a temporary directory. Use `pnpm run build` to run everything in the right order.\n\n## Issues\n\nThis project uses Github issues.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolbuilder%2Fiterablefu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoolbuilder%2Fiterablefu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolbuilder%2Fiterablefu/lists"}