SpanUtils is a .NET library providing utilities and extensions for working with System.Span
- Supports various utility enumerators for enumerating values inside spans
To install SpanUtils run:
dotnet add package SpanUtils
After installation to utilize the extensions add the following using statement:
using SpanUtils.Extensions;
Now the various extension methods are available:
using SpanUtils.Extensions;
using System.Diagnostics;
int chunkSize = 2;
int[] data = new[] { 0, 1, 2, 3, 4, 5};
int[][] expectedChunks = new[]
{
new[] { 0, 1 },
new[] { 2, 3 },
new[] { 4, 5 },
};
int index = 0;
foreach (Span<int> chunk in data.EnumerateChunks(chunkSize, exact: true))
{
Debug.Assert(chunk.SequenceEqual(expectedChunks[index]));
++index;
}
For more examples of usage see the tests in tests/SpanUtils.Tests
SpanUtils is licensed under the MIT License