{"id":21186825,"url":"https://github.com/patrickroberts/enumerable-ts","last_synced_at":"2025-03-14T20:18:55.230Z","repository":{"id":57225794,"uuid":"153851934","full_name":"patrickroberts/enumerable-ts","owner":"patrickroberts","description":"A port of System.Linq.Enumerable from the .NET framework to TypeScript","archived":false,"fork":false,"pushed_at":"2019-03-22T22:56:08.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T10:19:08.957Z","etag":null,"topics":["deferred-tasks","enumerable","extension-methods","iterable","iterator","prototype-chain","typescript"],"latest_commit_sha":null,"homepage":"","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/patrickroberts.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":"2018-10-19T23:27:43.000Z","updated_at":"2019-12-04T22:35:46.000Z","dependencies_parsed_at":"2022-08-24T10:40:20.726Z","dependency_job_id":null,"html_url":"https://github.com/patrickroberts/enumerable-ts","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fenumerable-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fenumerable-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fenumerable-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fenumerable-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickroberts","download_url":"https://codeload.github.com/patrickroberts/enumerable-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243639558,"owners_count":20323511,"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":["deferred-tasks","enumerable","extension-methods","iterable","iterator","prototype-chain","typescript"],"created_at":"2024-11-20T18:26:25.649Z","updated_at":"2025-03-14T20:18:55.205Z","avatar_url":"https://github.com/patrickroberts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enumerable-ts\n\nA port of System.Linq.Enumerable from the .NET framework to TypeScript, using a unique and safe design pattern which directly exposes the Enumerable class as a collection of polymorphic extension methods to all of the classes defined in the core language specification that implement the iterable protocol.\n\n## Why enumerable-ts?\n\nenumerable-ts is designed to fulfill the same purpose as the Enumerable class from C#. It provides a collection of extension methods to the built-in classes and uses deferred execution for declaring complex queries and iterating large collections with efficient memory consumption.\n\nThis is possible through the use of [generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*). Generator functions provide a way of expressing deferred execution consumed through the [iterator protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol). This allows complex queries to be constructed and iterated without buffering intermediate copies of the entire underlying collection in memory.\n\n## Usage\n\n#### Installing\n\n```bash\n$ npm i --save enumerable-ts\n```\n\n#### ES2015\n\n```ts\nimport 'enumerable-ts'\n```\n\n#### CommonJS\n\n```ts\nrequire('enumerable-ts')\n```\n\n### Example\n\n```ts\nconst array: (number | null)[] = [1, 2, 3, 4, null, 6, 7, 8, 9]\nconst sum = array\n  .where(Boolean)\n  .select(i =\u003e i * 2)\n  .aggregate((sum, val) =\u003e sum + val, 0)\n\nconsole.log(sum) // 80\n```\n\nBecause of deferred execution, the original `array` is only iterated _once_ by `aggregate()`, which calls and consumes `this[Symbol.iterator]` to yield the sequence of non-null, doubled integers being summed.\n\n### Array methods and their deferred counterparts\n\n* `array.concat(…)` -\u003e `enumerable.concat(…)`*\n* `array.every(…)` -\u003e `enumerable.all(…)`\n* `array.filter(…)` -\u003e `enumerable.where(…)`\n* `array.find(…)` -\u003e `enumerable.first(…)`\n* `array.flatMap(…)` -\u003e `enumerable.selectMany(…)`\n* `array.map(…)` -\u003e `enumerable.select(…)`\n* `array.reduce(…)` -\u003e `enumerable.aggregate(…)`\n* `array.reduceRight(…)` -\u003e `enumerable.aggregateRight(…)`\n* `array.reverse()` -\u003e `enumerable.reverse(…)`*\n* `array.slice(begin)` -\u003e `enumerable.skip(begin)`\n* `array.slice(begin, end)` -\u003e `enumerable.skip(begin).take(end - begin)`\n* `array.some(…)` -\u003e `enumerable.any(…)`\n* `array.sort(…)` -\u003e `enumerable.orderBy(…)`\n\n\u003csup\u003e* To call these methods on an array, use `array.toEnumerable().method(…)` or `Enumerable.prototype.method.call(array, …)`\u003c/sup\u003e\n\nOn the left-hand side, the operation occurs immediately and returns the result. If the result is an array, the operation on the right-hand side is deferred and an `Enumerable` is returned, which will apply the operation when it is iterated implicitly using `for...of` or explicitly using `enumerable[Symbol.iterator]()`. If the result is a boolean, element, or accumulator, then the operation on the right-hand side still occurs immediately, but the method is available on `Enumerable.prototype`, while the left-hand side is not.\n\nThere are many more methods available on [`IEnumerable`](docs/IEnumerable.md).\n\n# [Documentation](docs/)\n\n## FAQ\n\n#### Can I use this without TypeScript?\n\nYes, the module is [available on npm](https://www.npmjs.com/package/enumerable-ts) pre-transpiled to ECMAScript 2015. There is no plan to make this backwards-compatible, as the only way to modify a built-in prototype chain (`__proto__`) is platform-specific and not standardized within the ECMAScript 5 specification.\n\n#### What built-in classes extend `Enumerable`?\n\n`Array`, `TypedArray`, `String`, `Map`, and `Set`.\n\n#### Why are `concat()`, `join()`, `reverse()`, and `toJSON()` only available on `Enumerable` and not on the `IEnumerable` interface?\n\nIn order to remain polymorphic, all the `IEnumerable` interface methods must be forward-compatible with the methods on each of its implementing classes. Since many of the built-in Iterables in JavaScript already implement these methods with conflicting signatures, it's by design that these methods are only available on instances of the concrete `Enumerable` class.\n\nHowever, by using explicit calls to these methods on the `Enumerable` class like `Enumerable.prototype.concat.join(array, …)`, they can still be directly applied to instances of the built-in classes without violating the principles of polymorphism.\n\n## Roadmap\n\n- [ ] Documentation of usage with example code\n- [x] Full port of core [`System.Linq.Enumerable`](https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable) methods\n- [ ] Full port of [MoreLINQ](https://github.com/morelinq/MoreLINQ) methods\n- [x] Node.js support\n- [ ] Browser support\n- [ ] Require.js support\n- [ ] Universal Module Definition\n- [ ] Separate exports with and without global-modifying side-effects (similar to [`colors`](https://www.npmjs.com/package/colors#usage))\n\n## Contributing\n\nDo you have feature requests, bug reports, or ideas for improving this project? Please open new issues on the [github repository](https://github.com/patrickroberts/enumerable-ts) with details about your inquiry.\n\n## License\n\nCopyright © 2018 Patrick Roberts\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroberts%2Fenumerable-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickroberts%2Fenumerable-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroberts%2Fenumerable-ts/lists"}