{"id":23209854,"url":"https://github.com/neon-sunset/rangeextensions","last_synced_at":"2025-08-19T04:32:47.440Z","repository":{"id":45733944,"uuid":"514066699","full_name":"neon-sunset/RangeExtensions","owner":"neon-sunset","description":"A set of optimized extensions which integrate System.Range with foreach and LINQ","archived":false,"fork":false,"pushed_at":"2024-01-17T06:08:35.000Z","size":117,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-17T06:36:35.488Z","etag":null,"topics":["csharp","dotnet","extension","ienumerable","performance","range"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/RangeExtensions/","language":"C#","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/neon-sunset.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-07-14T22:40:14.000Z","updated_at":"2024-12-08T06:00:38.000Z","dependencies_parsed_at":"2023-09-29T12:33:05.871Z","dependency_job_id":"fcdfd50b-4c66-4e59-80a1-e4bdbae32c22","html_url":"https://github.com/neon-sunset/RangeExtensions","commit_stats":{"total_commits":87,"total_committers":4,"mean_commits":21.75,"dds":"0.49425287356321834","last_synced_commit":"59b9775da991584561b6c91b3c7e8822f62597b5"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neon-sunset%2FRangeExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neon-sunset%2FRangeExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neon-sunset%2FRangeExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neon-sunset%2FRangeExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neon-sunset","download_url":"https://codeload.github.com/neon-sunset/RangeExtensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230320865,"owners_count":18208265,"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":["csharp","dotnet","extension","ienumerable","performance","range"],"created_at":"2024-12-18T18:29:54.939Z","updated_at":"2024-12-18T18:29:55.445Z","avatar_url":"https://github.com/neon-sunset.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RangeExtensions\n[![CI/CD](https://github.com/neon-sunset/RangeExtensions/actions/workflows/dotnet-releaser.yml/badge.svg)](https://github.com/neon-sunset/RangeExtensions/actions/workflows/dotnet-releaser.yml) [![nuget](https://badgen.net/nuget/v/RangeExtensions/latest)](https://www.nuget.org/packages/RangeExtensions/) [![Coverage Status](https://coveralls.io/repos/github/neon-sunset/RangeExtensions/badge.svg)](https://coveralls.io/github/neon-sunset/RangeExtensions)\n\nThis package enables the usage of `System.Range` in `foreach` expressions and provides extensions to integrate it with LINQ as a faster replacement to `Enumerable.Range`.\n\n- Correctness is verified against `IEnumerable\u003cint\u003e` and `Enumerable.Range` behavior;\n- Implementation tries its best to make abstractions either zero-cost or reasonably close to that. For critical paths, performance is tuned to be allocation-free and on par with regular `for` loops\n\n## Features\n### Range enumeration\n```cs\nforeach (var i in ..100) // you can write 0..Length as just ..Length\n{\n    Console.WriteLine(i);\n}\n```\n\n### Reverse range enumeration\n```cs\nfor (var i = 100 - 1; i \u003e= 0; i--)\n{\n    Console.WriteLine(i);\n}\n\n// Can be written as\nforeach (var i in 100..0)\n{\n    Console.WriteLine(i);\n}\n```\n\n### Select and Where\n```cs\nvar floats = (0..100).Select(i =\u003e (float)i);\nvar odd = (0..100).Where(i =\u003e i % 2 != 0);\n\nvar randomNumbers = (0..1000)\n    .Select(_ =\u003e Random.Shared.Next())\n    .ToArray();\n```\n\n### Collecting to array or list\n```cs\nvar numbers = (0..100).ToArray();\n```\n\n### Aggregate\n```cs\nvar digits = (0..10)\n    .Aggregate(new StringBuilder(), (sb, i) =\u003e sb.Append(i))\n    .ToString();\n\nAssert.Equal(\"0123456789\", digits);\n```\n\n### Other LINQ specializations\n```cs\nvar enumerable = (..100).AsEnumerable();\n\nvar sum = enumerable.Sum();\nvar count = enumerable.Count;\nvar average = enumerable.Average();\nvar firstTen = enumerable.Take(10);\nvar reversed = enumerable.Reverse();\n// and others\n```\n\n## Performance\nIn .NET 7, `foreach (var i in 0..Length)` has the same performance as `for` loop. Otherwise, `RangeExtensions` is 2 to \u003e10 times faster than `Enumerable.Range`. Using DynamicPGO significantly improves the performance of both.\n``` ini\nBenchmarkDotNet=v0.13.2, OS=macOS 13.1 (22C65) [Darwin 22.2.0]\nApple M1 Pro, 1 CPU, 8 logical and 8 physical cores\n.NET SDK=8.0.100-alpha.1.22620.11\n  [Host]     : .NET 7.0.1 (7.0.122.56804), Arm64 RyuJIT AdvSIMD\n  DefaultJob : .NET 7.0.1 (7.0.122.56804), Arm64 RyuJIT AdvSIMD\n\nJob=ShortRun  IterationCount=3  LaunchCount=1  \nWarmupCount=3\n\nDOTNET_TieredPGO=1\nDOTNET_ReadyToRun=0\n```\n|                Method | Length |            Mean |         Error | Ratio | Allocated |\n|---------------------- |------- |----------------:|--------------:|------:|----------:|\n|                   For |      1 |       0.0000 ns |     0.0000 ns |     ? |         - |\n|                 **Range** |      1 |       0.6531 ns |     0.0051 ns |     ? |         - |\n|       EnumerableRange |      1 |       8.1135 ns |     0.0198 ns |     ? |      40 B |\n|           **RangeSelect** |      1 |       1.1588 ns |     0.0048 ns |     ? |         - |\n|      EnumerableSelect |      1 |      40.7948 ns |     0.7697 ns |     ? |      88 B |\n|      **RangeSelectTwice** |      1 |      19.4165 ns |     0.0480 ns |     ? |      96 B |\n| EnumerableSelectTwice |      1 |      43.6399 ns |     0.0908 ns |     ? |     232 B |\n|            **RangeWhere** |      1 |       1.3954 ns |     0.0036 ns |     ? |         - |\n|       EnumerableWhere |      1 |      26.1945 ns |     0.0534 ns |     ? |      96 B |\n|                       |        |                 |               |       |           |\n|                   For |    100 |      36.1897 ns |     0.0618 ns |  1.00 |         - |\n|                 **Range** |    100 |      36.9244 ns |     2.0789 ns |  1.00 |         - |\n|       EnumerableRange |    100 |     211.4774 ns |     0.6430 ns |  5.85 |      40 B |\n|           **RangeSelect** |    100 |      42.6852 ns |     0.1689 ns |  1.18 |         - |\n|      EnumerableSelect |    100 |     235.7174 ns |     0.5161 ns |  6.51 |      88 B |\n|      **RangeSelectTwice** |    100 |     110.1340 ns |     0.1667 ns |  3.04 |      96 B |\n| EnumerableSelectTwice |    100 |     298.2976 ns |     2.7831 ns |  8.22 |     232 B |\n|            **RangeWhere** |    100 |      56.1455 ns |     0.1701 ns |  1.55 |         - |\n|       EnumerableWhere |    100 |     249.1264 ns |     1.5890 ns |  6.89 |      96 B |\n|                       |        |                 |               |       |           |\n|                   For | 100000 |  31,167.5682 ns |    37.3266 ns |  1.00 |         - |\n|                 **Range** | 100000 |  31,173.8688 ns |    13.0666 ns |  1.00 |         - |\n|       EnumerableRange | 100000 | 212,925.2827 ns |   156.8182 ns |  6.83 |      40 B |\n|           **RangeSelect** | 100000 |  50,086.3342 ns |    39.0657 ns |  1.61 |         - |\n|      EnumerableSelect | 100000 | 204,113.5813 ns |   100.0221 ns |  6.55 |      88 B |\n|      **RangeSelectTwice** | 100000 |  94,302.1444 ns |   230.6254 ns |  3.02 |      96 B |\n| EnumerableSelectTwice | 100000 | 203,946.9247 ns |   908.5243 ns |  6.56 |     232 B |\n|            **RangeWhere** | 100000 |  47,165.0569 ns |    36.7208 ns |  1.51 |         - |\n|       EnumerableWhere | 100000 | 209,918.1519 ns | 3,298.4418 ns |  6.76 |      96 B |\n\nMore details on performance: [Releases](https://github.com/neon-sunset/RangeExtensions/releases) tab contains notes on improvements introduced with each version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneon-sunset%2Frangeextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneon-sunset%2Frangeextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneon-sunset%2Frangeextensions/lists"}