{"id":26192774,"url":"https://github.com/asynched/iter-ts","last_synced_at":"2026-04-14T23:32:30.396Z","repository":{"id":48412880,"uuid":"516891053","full_name":"asynched/iter-ts","owner":"asynched","description":"A utility library for JavaScript generators.","archived":false,"fork":false,"pushed_at":"2022-07-26T05:55:55.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-12T09:40:30.737Z","etag":null,"topics":["generators","iterables","javascript","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/iter-ts","language":"TypeScript","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/asynched.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-22T21:27:22.000Z","updated_at":"2023-03-07T08:02:37.000Z","dependencies_parsed_at":"2022-08-31T18:51:14.750Z","dependency_job_id":null,"html_url":"https://github.com/asynched/iter-ts","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/asynched/iter-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynched%2Fiter-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynched%2Fiter-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynched%2Fiter-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynched%2Fiter-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asynched","download_url":"https://codeload.github.com/asynched/iter-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asynched%2Fiter-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31819718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"ssl_error","status_checked_at":"2026-04-14T18:05:01.765Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["generators","iterables","javascript","typescript"],"created_at":"2025-03-12T01:24:41.241Z","updated_at":"2026-04-14T23:32:30.367Z","avatar_url":"https://github.com/asynched.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iter-ts\n\nIterables with methods for JavaScript/Typescript! 🎉\n\n## About\n\nThis library aims to implement utility methods for iterable objects in Javascript/Typescript. As you'll see in the docs, an `Iter` object can be created from pretty much anything that exposes an iterable interface.\n\n## Installation\n\nFirst, you've gotta install the library with:\n\n- npm\n\n```sh\nnpm i iter-ts\n```\n\n- yarn\n\n```sh\nyarn add iter-ts\n```\n\n\u003e You're now ready to use iter-ts! 🥳\n\n## The gist\n\nImagine you need to iterate over something, that might be an `Array` of some sorts or a `generator` function and need to do some operations on that iterable. In the case below, we'll be iterating over a Fibonacci generator function and operating over each entry.\n\n```ts\nimport Iter from 'iter-ts'\n\n// This is our generator function.\n// In here, we can request as many\n// terms as we'd like.\nfunction* fibonacci(terms: number) {\n  let n1 = 1\n  let n2 = 1\n  let nextTerm: number\n\n  for (let i = 1; i \u003c= n; i++) {\n    yield n1\n    nextTerm = n1 + n2\n    n1 = n2\n    n2 = nextTerm\n  }\n}\n\n// First, we're going to build an Iter\n// object from the generator function.\n// We'll do that by using the method\n// `.fromGenerator` on the Iter class.\nconst values = Iter\n  // In here, we'll make a generator with\n  // an infinite number of terms.\n  // And yes, we can do that without killing the CPU!\n  .fromGenerator(() =\u003e fibonacci(Infinity))\n  // We'll take the first 10 terms from the sequence.\n  .take(10)\n  // We'll inspect each term.. Because debugging!\n  .inspect((term) =\u003e console.log(term))\n  // After inspecting the terms, we'll double each one.\n  .map((term) =\u003e term * 2)\n  // We'll filter them, taking only the even numbers.\n  .filter((term) =\u003e term % 2 === 0)\n  // And we'll collect then into an array of numbers.\n  .collect()\n\n// Now we have a list of values from our\n// generator function.\nconsole.log(values)\n```\n\n- But why does it even work? Wasn't the `fibonacci` function called with `Infinity`?\n\nYes, indeed. The generator function was called with `Infinity` as a parameter, **but...** Javascript generators are lazy, as the terms will only be evaluated as the generator is called. This allows us to call the `fibonacci` generator with as many terms as we want without killing the Javascript runtime, as they'll only be evaluated when a term from the generator is requested.\n\nIn the example above, the generator is only requested on the `.collect()` method call, since we only want to take 10 items out of the generator, the Javascript runtime is smart enough to yield us only 10 entries, of which we perform operations later.\n\n\u003e Cool, isn't it?\n\nThis pattern doesn't only apply to numbers, as we can make an `Iter` object out of anything that exposes an `Iterable` interface.\n\n## Before proceeding further\n\nIterables are really cool, and being able to perform operations on them is really nice, **BUT...** Operating over them in this pattern hinders us a perform penalty. Iter methods are not as performant as `Array` operations, comparing the speed between the two, we found the results:\n\n- 10.000 entries\n\n| Object | Runtime |\n| ------ | ------- |\n| Array  | 0ms     |\n| Iter   | 4ms     |\n\n- 100.000 entries\n\n| Object | Runtime |\n| ------ | ------- |\n| Array  | 4ms     |\n| Iter   | 14ms    |\n\n- 1.000.000 entries\n\n| Object | Runtime |\n| ------ | ------- |\n| Array  | 22ms    |\n| Iter   | 96ms    |\n\n\u003e Mapping over `n` entries of an `Array` / `Iter`, doubling the value of each entry.\n\nSo, why should I use this if it is clearly slower than the array alternative?\n\n- Although arrays are much faster than the iter alternative, they use much more memory;\n- Performing operations on a big array might result in an exception in different runtimes, as the process will take too much memory;\n- Array operations aren't lazy, they'll execute as long as you tell the computer to do it.\n\nAs operating over `Iter` objects is lazy by default, you get the benefits:\n\n- Much less memory consumption, as the value can be dropped after an iteration of the `Iter`;\n- Nicer iteration utilities, such as `take`, `fold`, `scan` and others;\n- You can still use arrays, as collecting an `Iter` will give you an array of the entries from your iterable;\n- Iters can be built from anything that is iterable, such as `strings`, `ranges` and `generators`.\n\n## Author\n\n| ![Eder Lima](https://github.com/asynched.png?size=100) |\n| ------------------------------------------------------ |\n| [Eder Lima](https://github.com/asynched)               |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasynched%2Fiter-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasynched%2Fiter-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasynched%2Fiter-ts/lists"}