RangeExtensions 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package RangeExtensions --version 1.0.0                
NuGet\Install-Package RangeExtensions -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RangeExtensions" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RangeExtensions --version 1.0.0                
#r "nuget: RangeExtensions, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RangeExtensions as a Cake Addin
#addin nuget:?package=RangeExtensions&version=1.0.0

// Install RangeExtensions as a Cake Tool
#tool nuget:?package=RangeExtensions&version=1.0.0                

RangeExtensions

CI/CD nuget Coverage Status

Extensions for Range type that provide support for 'foreach' and additional IEnumerable-compatible features.

  • Correctness is verified against standard IEnumerable<int> behavior.
  • Performance is hand tuned to produce efficient native code with no allocations as long as RangeEnumerable isn't boxed into IEnumerable<int> (same applies to enumerator).

Features

Range enumeration

foreach (var i in 0..100)
{
    Console.WriteLine(i);
}

Reverse range enumeration

for (var i = 100 - 1; i >= 0; i--)
{
    Console.WriteLine(i);
}

// Can be written as
foreach (var i in 100..0)
{
    Console.WriteLine(i);
}

Collecting to array or list

var numbers = (0..100).ToArray();

Other IEnumerable APIs (some methods have bespoke implementations for performance)

var firstTen = (400...720).AsEnumerable().Take(10);

Performance

In short: 10x fast vs Enumerable.Range().


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
AMD Ryzen 7 5800X, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.100-rc.1.22363.32
  [Host]   : .NET 7.0.0 (7.0.22.36203), X64 RyuJIT
  ShortRun : .NET 7.0.0 (7.0.22.36203), X64 RyuJIT

Job=ShortRun  IterationCount=3  LaunchCount=1  
WarmupCount=3  

Method Length Mean Error StdDev Ratio RatioSD Code Size Gen 0 Allocated
For 100 23.94 ns 0.556 ns 0.030 ns 1.00 0.00 20 B - -
Range 100 24.91 ns 0.138 ns 0.008 ns 1.04 0.00 65 B - -
RangeReverse 100 27.40 ns 0.245 ns 0.013 ns 1.14 0.00 65 B - -
EnumerableRange 100 269.46 ns 52.032 ns 2.852 ns 11.25 0.13 322 B 0.0024 40 B
RangeAsEnumerable 100 24.92 ns 0.522 ns 0.029 ns 1.04 0.00 67 B - -
For 10000 2,085.24 ns 300.295 ns 16.460 ns 1.00 0.00 20 B - -
Range 10000 2,085.39 ns 308.278 ns 16.898 ns 1.00 0.00 65 B - -
RangeReverse 10000 2,078.58 ns 81.149 ns 4.448 ns 1.00 0.01 65 B - -
EnumerableRange 10000 27,364.70 ns 616.148 ns 33.773 ns 13.12 0.11 322 B - 40 B
RangeAsEnumerable 10000 2,104.25 ns 464.044 ns 25.436 ns 1.01 0.01 67 B - -
For 10000000 2,086,119.92 ns 289,496.016 ns 15,868.253 ns 1.00 0.00 20 B - -
Range 10000000 2,086,358.07 ns 335,673.174 ns 18,399.379 ns 1.00 0.02 65 B - -
RangeReverse 10000000 2,083,810.55 ns 342,667.388 ns 18,782.756 ns 1.00 0.01 65 B - -
EnumerableRange 10000000 27,263,256.25 ns 396,121.214 ns 21,712.740 ns 13.07 0.09 322 B - -
RangeAsEnumerable 10000000 2,075,666.41 ns 45,777.672 ns 2,509.229 ns 1.00 0.01 67 B - -
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.0

  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on RangeExtensions:

Repository Stars
U8String/U8String
[work-in-progress] Highly functional and performant UTF-8 string primitive for C#
Version Downloads Last updated
2.1.1 44,610 1/9/2023
2.1.0 306 1/8/2023
2.0.0 315 12/23/2022
1.2.2 712 9/3/2022
1.2.1 392 8/13/2022
1.2.0 380 8/10/2022
1.1.0 384 7/28/2022
1.0.0 405 7/16/2022