Add the package
dotnet add package collection-iterable-methods --version 2.0.3Write less boilerplate. Build expressive pipelines. Bring familiar Filter, Map, and Reduce methods to .NET with strong types, optimized operations, and zero package dependencies.
dotnet add package collection-iterable-methodsOpen source · MIT licensed · No package dependencies
using CollectionIterable;
var numbers = new[] { 1, 2, 3, 4, 5, 6 };
var labels = numbers
.Filter(n => n % 2 == 0)
.Map(n => $"Item {n}")
.ToArray();
// ["Item 2", "Item 4", "Item 6"]
Names you know.
Types you can trust.
Arrays, lists, and streams.
Works alongside LINQ.
Optimized collection operations.
Async and parallel, built in.
Getting started
Works with .NET 8, .NET 9, .NET 10, and later compatible versions. Add the package, import a namespace, and use the methods directly on your collection.
View package on NuGet ↗dotnet add package collection-iterable-methods --version 2.0.3using CollectionIterable;
var total = new[] { 10, 20, 30 }
.Filter(price => price > 10)
.Reduce((sum, price) => sum + price, 0);
// 50Results are ordinary .NET values and collections. Chain lazy results with LINQ, or materialize them with ToArray() when you need a snapshot.
Built for the way you work
Compose elegant pipelines, await CPU work,
and put parallel processing to work.
Filter and Map defer work until enumeration. Map between different types without losing inference.
Indexed callbacks are available too. Use Map((value, index) => ...) when position matters.
using CollectionIterable;
var names = new[] { "Ada", "Linus", "Grace" };
var labels = names
.Filter(name => name.Length > 3)
.Map((name, index) => $"{index + 1}. {name}")
.ToArray();
// ["1. Linus", "2. Grace"]FilterAsync runs a synchronous predicate on a worker thread and materializes the result before the task completes.
Keep your calling thread free while synchronous callbacks run in the background. Await the task to access completed results.
using CollectionIterableAsync;
var numbers = new[] { 1, 2, 3, 4, 5, 6 };
var evens = await numbers.FilterAsync(n => n % 2 == 0);
// Work is finished when await returns.
// evens contains 2, 4, 6.Use IIterableOptions to set the degree of parallelism and a cancellation token.
Choose the concurrency level that fits your application, with cooperative cancellation built in. See the API guide for callback and ordering requirements.
using CollectionIterableParallel;
using CollectionIterableUtils;
using var cancellation = new CancellationTokenSource();
var options = new IIterableOptions
{
parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 4
},
cancellationToken = cancellation.Token
};
var evens = new[] { 1, 2, 3, 4, 5, 6 }
.FilterParallel(n => n % 2 == 0, options);
// Contains 2, 4, 6. Order is unspecified.API at a glance
From a quick filter to a complete pipeline,
find the operation you need.
| Method | Purpose | What you get |
|---|---|---|
Filter / Map | Keep matching items / transform types | Lazy, ordered; replayable if the source is |
Slice | Select a range | Efficient, bounded enumeration of a range |
Reduce / ForEach | Accumulate a value / visit each item | Complete synchronously |
Concat | Join two collections | Immediate copy for arrays/collections; lazy for general enumerables |
ToRecord | Create a dictionary | Direct key/value projection into a dictionary |
SortCollection | Sort by a key | Cached sort keys while preserving the source collection |
FilterAsync / ConcatAsync / ForEachAsync | Offload synchronous work | Task.Run; work completes before await returns |
FilterParallel / FilterParallelAsync | Filter concurrently | Complete before return/await; unordered output |
ForEachParallel / ForEachParallelAsync | Visit items concurrently | Configurable parallelism for concurrent processing |
SortCollectionParallel | Sort with a parallel path | Adaptive sorting with sequential and parallel paths |
ToDictionaryParallel | Create a dictionary concurrently | Concurrent dictionary construction with an IDictionary result |
NamespacesCollectionIterable · CollectionIterableAsync · CollectionIterableParallel · CollectionIterableUtils
Cancellation & concurrency
Cancellation is cooperative. Either supplied token can cancel; options are copied, never mutated. Default maximum parallelism is five.
Performance you can measure
Map up to 9.89× faster, filter up to 4.61× faster, and slice up to 12.43× faster in the recorded comparison. Optimized core operations make readable collection code even more rewarding.
Read the full benchmark report ↗Two final comparison runs. Explore the measured gains operation by operation.
Selected-operation peaks across tested inputs, comparing 2.0 candidate source with 1.0.2 source. Full methodology and results in the report.Discover version 2
Transform between types with generalized Map, await completed collection results, and manage parallel operations with configurable cancellation.
Turn numbers into labels, records into view models, and raw values into the shapes your application needs. C# infers both types for concise, expressive code.
Async filtering and concatenation finish their work before the task completes, giving you results that are ready to use.
Set concurrency and cancellation through IIterableOptions. Use ForEachParallelAsync to await parallel iteration and observe completion.
Part of your .NET toolkit
Install in seconds. Start with a familiar method. Build a pipeline your team will love to read.