{"id":18545328,"url":"https://github.com/xeinebiu/ts-iterable","last_synced_at":"2026-04-13T17:31:18.301Z","repository":{"id":61454385,"uuid":"549863198","full_name":"xeinebiu/ts-iterable","owner":"xeinebiu","description":"Iterables, streams for typescript","archived":false,"fork":false,"pushed_at":"2022-10-15T21:03:02.000Z","size":110,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-04T23:55:39.503Z","etag":null,"topics":["array","enumerable","enumeration","filter","first","group","iterable","iterables","iterator","iterators","javascript","list","map","mapnotnull","node","nodejs","sort","typescript","where","wherenotnull"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/xeinebiu.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":"2022-10-11T21:22:41.000Z","updated_at":"2022-10-15T04:48:45.000Z","dependencies_parsed_at":"2022-10-18T07:51:29.130Z","dependency_job_id":null,"html_url":"https://github.com/xeinebiu/ts-iterable","commit_stats":null,"previous_names":["xeinebiu/ts-enumerable"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xeinebiu/ts-iterable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fts-iterable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fts-iterable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fts-iterable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fts-iterable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xeinebiu","download_url":"https://codeload.github.com/xeinebiu/ts-iterable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fts-iterable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31762462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"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":["array","enumerable","enumeration","filter","first","group","iterable","iterables","iterator","iterators","javascript","list","map","mapnotnull","node","nodejs","sort","typescript","where","wherenotnull"],"created_at":"2024-11-06T20:19:45.716Z","updated_at":"2026-04-13T17:31:18.282Z","avatar_url":"https://github.com/xeinebiu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Iterable for Typescript\n\nSimilar to what we know from ``C#``, `Dart` or any other language which supports them,\nwe use Iterables to stream over collections.\n\n## Why using the Iterable?\n\nIterables are useful when you want to chain several operations on a collection such as\n\n- filter\n- filterNotNull\n- group\n- sort\n- map\n- mapNotNull\n- take\n- skip\n- every\n- none\n- some\n- etc ...\n\nFor example, lets consider a case. We need to work with a collection to filter the numbers greater than ``20``, map to\nthe string only the 3'rd value.\n\n- Without the Iterable\n\n````typescript\nconst data = [1, 10, 20, 30, 40, 50, ...];\nconst filteredData = data.filter(x =\u003e x \u003e 20);\nconst value = filteredData[3];\nconst mappedValue = value.toString();\n\n// result \"50\"\n````\n\n- Using the Iterable\n\n````typescript\nconst data = [1, 10, 20, 30, 40, 50, ...];\nconst mappedValue = asIterable(data)\n    .filter(x =\u003e x \u003e 20)\n    .skip(2)\n    .map(x =\u003e x.toString())\n    .first()\n\n// result \"50\"\n````\n\nThe Iterable code would be similar as \n````typescript\nlet skipped = 0;\nfor (let i = 0; i \u003c data.length; i++) {\n    const element = data[i];\n    if (element \u003e 20 \u0026\u0026 ++skipped \u003c 2) return element.toString();\n}\nthrow new NoElementError();\n````\n\nNot only the difference stays that we have written it differently, but also how much data was processed.\n\nOn the example without using the ``Iterable``\n\n- All elements of the collection are visited and filtered\n- The third element is retrieved\n- The retrieved element is mapped to a string\n\nNow, if the collection is really huge, this will take time to process.\n\nWhile, using the ``Iterable``, that is not necessarily as we know we do not need all the elements.\nBecause we call ``first()`` at the end, that means that the operation will stop as soon this condition is meet.\n\n- Find from collection only the first value that is greater than `20`\n- Map the value to a string\n\n## Installation\n\n````shell\nnpm i @xeinebiu/ts-iterable\n````\n\n## Examples\n\n### Convert a list to iterable\n\n````typescript\nconst data = [1, 2, 3, 4, 5];\nconst iterable = asIterable(data);\n````\n\n### Filter\n\n````typescript\n// without the Iterable\nconst filtered = data.filter(x =\u003e x \u003c 4);\n\n// with iterable\nconst filtered = asIterable(data)\n    .filter(x =\u003e x \u003c 4)\n    .toList();\n\n// result [1, 2, 3]\n````\n\n### Filter Not Null\n\nFilter `undefined|null` values out\n\n````typescript\nconst data = [1, 2, null, 3, undefiend, 4];\nconst filtered = asIterable(data)\n    .filterNotNull();\n\n// result [1, 2, 3, 4]\n````\n\n### Take\n\nTake specific amount of elements\n\n````typescript\n// without iterable\nconst taken = data.slice(0, 3);\n\n// with iterable\nconst taken = asIterable(data)\n    .take(3)\n    .toList();\n\n// result [1, 2, 3]\n````\n\n### Every\n\nReturn `true` if all elements match the predicate.\n\n````typescript\nconst result = asIterable(data)\n    .every(x =\u003e x.toString() !== \"hello world\");\n\n// result true\n````\n\n### Some\n\nReturn `true` if any of the elements match the predicate\n\n````typescript\nconst result = asIterable(data)\n    .some(x =\u003e x.toString() !== \"1\");\n\n// result true\n````\n\n### None\n\nReturn `true` if all the elements do not match the predicate\n\n````typescript\nconst result = asIterable(data)\n    .none(x =\u003e x \u003c= -1);\n\n// result true\n````\n\n### First\n\nReturn the first element if available, otherwise throw ``NoElementError``\n\n````typescript\nconst result = asIterable(data)\n    .filter(x =\u003e x \u003e 4)\n    .first();\n\n// result 5\n````\n\n### First Or Null\n\nReturn the first element if available, otherwise null.\n\n````typescript\nconst result = asIterable(data)\n    .filter(x =\u003e x \u003e 100)\n    .firstOrNull();\n\n// result null\n````\n\n### Map\n\nMap the elements using a mapper\n\n````typescript\nconst result = asIterable(data)\n    .filter(x =\u003e x \u003c 3)\n    .map(x =\u003e x.toString())\n    .toList();\n\n// result [\"1\", \"2\"]\n````\n\n### Map Not Null\n\nMap the elements using the mapper and avoid inserting `null|undefined` values in the list\n\n````typescript\nconst data = [1, null, 2, undefined, 3];\n\nconst result = asIterable(data)\n    .filter(x =\u003e x \u003c 3)\n    .mapNotNull(x =\u003e x?.toString())\n    .toList();\n\n// result [\"1\", \"2\", \"3\"]\n````\n\n### Skip\n\nOffset the elements cursor starting from index 0\n\n````typescript\nconst result = asIterable(data)\n    .skip(1)\n    .toList();\n\n// result [\"2\", \"3\", \"4\", \"5\"]\n````\n\n### Take\n\nTake specific amount of elements\n\n````typescript\nconst result = asIterable(data)\n    .take(2)\n    .toList();\n\n// result [\"1\", \"2\"]\n````\n\n### Sort\n\nSort all elements and return new [ExtendedIterable]\n\n````typescript\nconst sorted = asIterable(data)\n    .sort((a, b) =\u003e b - a)\n    .toList();\n\n// result [5, 4, 3, 2, 1]\n````\n\n### Group\n\nGroup all elements and return new [ExtendedIterable]\n\n````typescript\nconst data = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n\nconst groupedData = asIterable(data)\n    .group(x =\u003e {\n        if (x \u003c 0) return \"negative\";\n        return \"positive\";\n    })\n    .toList();\n\n// result\n// [\n//     [\"negative\", [-9, -8, -7, -6, -5, -4, -3, -2, -1]],\n//     [\"positive\", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]\n// ];\n````\n\n### To List\n\nConvert the Iterable to a collection.\n\n````typescript\nconst list = asIterable(data)\n    .toList();\n\n// result [1, 2, 3, 4, 5]\n````\n\n## MIT\n### The MIT License\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeinebiu%2Fts-iterable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeinebiu%2Fts-iterable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeinebiu%2Fts-iterable/lists"}