Philiprehberger.ChunkList
0.1.10
dotnet add package Philiprehberger.ChunkList --version 0.1.10
NuGet\Install-Package Philiprehberger.ChunkList -Version 0.1.10
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="Philiprehberger.ChunkList" Version="0.1.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.ChunkList" Version="0.1.10" />
<PackageReference Include="Philiprehberger.ChunkList" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Philiprehberger.ChunkList --version 0.1.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Philiprehberger.ChunkList, 0.1.10"
#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.
#:package Philiprehberger.ChunkList@0.1.10
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Philiprehberger.ChunkList&version=0.1.10
#tool nuget:?package=Philiprehberger.ChunkList&version=0.1.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Philiprehberger.ChunkList
Split any IEnumerable into fixed-size chunks with a simple static method or LINQ-style extension.
Installation
dotnet add package Philiprehberger.ChunkList
Usage
using Philiprehberger.ChunkList;
var numbers = Enumerable.Range(1, 10);
// Static method
foreach (var chunk in EnumerableChunker.Chunk(numbers, 3))
{
Console.WriteLine(string.Join(", ", chunk));
}
// 1, 2, 3
// 4, 5, 6
// 7, 8, 9
// 10
// Extension method
var chunks = numbers.ChunkBy(4).ToList();
// chunks[0] == [1, 2, 3, 4]
// chunks[1] == [5, 6, 7, 8]
// chunks[2] == [9, 10]
// Works with any sequence
var words = new[] { "a", "b", "c", "d", "e" };
var pairs = words.ChunkBy(2);
// ["a","b"], ["c","d"], ["e"]
Custom Chunk Size
using Philiprehberger.ChunkList;
var items = Enumerable.Range(1, 10);
var pairs = EnumerableChunker.Chunk(items, 2);
// [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
Extension Method
using Philiprehberger.ChunkList;
var names = new[] { "Alice", "Bob", "Charlie", "Dave", "Eve" };
foreach (var group in names.ChunkBy(2))
{
Console.WriteLine(string.Join(", ", group));
}
// Alice, Bob
// Charlie, Dave
// Eve
Edge Cases
using Philiprehberger.ChunkList;
var empty = Array.Empty<int>().ChunkBy(3); // yields nothing
var small = new[] { 1, 2 }.ChunkBy(5); // [[1, 2]] — single chunk
API
EnumerableChunker
| Method | Description |
|---|---|
Chunk<T>(IEnumerable<T> source, int size) |
Yield IReadOnlyList<T> chunks of at most size elements |
ChunkExtensions
| Method | Description |
|---|---|
ChunkBy<T>(this IEnumerable<T> source, int size) |
Extension method — same as EnumerableChunker.Chunk |
Notes:
- The last chunk may contain fewer than
sizeelements. - Throws
ArgumentOutOfRangeExceptionifsizeis zero or negative. - Enumeration is lazy — chunks are produced on demand.
Development
dotnet build src/Philiprehberger.ChunkList.csproj --configuration Release
Support
If you find this project useful:
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.