collection-iterable-methods 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package collection-iterable-methods --version 2.0.0
                    
NuGet\Install-Package collection-iterable-methods -Version 2.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="collection-iterable-methods" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="collection-iterable-methods" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="collection-iterable-methods" />
                    
Project file
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 collection-iterable-methods --version 2.0.0
                    
#r "nuget: collection-iterable-methods, 2.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.
#:package collection-iterable-methods@2.0.0
                    
#: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=collection-iterable-methods&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=collection-iterable-methods&version=2.0.0
                    
Install as a Cake Tool

collection-iterable-methods

Node-style collection names for .NET 8, backed by LINQ and specialized paths where measurements justify them. Version 2.0.0 includes a deliberate Map API change; see the migration notes below.

using CollectionIterable;
using CollectionIterableAsync;

var numbers = new[] { 1, 2, 3, 4, 5 };
var evens = numbers.Filter(number => number % 2 == 0);
var labels = numbers.Map(number => $"Item {number}");
var indexed = numbers.Map((number, index) => $"{index}: {number}");
var sum = numbers.Reduce((total, number) => total + number, 0);
var sorted = numbers.SortCollection(number => number);
var completed = await numbers.FilterAsync(number => number > 2);

Contracts

Methods Execution / ordering
Filter, Map Lazy, ordered, replayable when the source is replayable
Slice Lazy, ordered, start inclusive/end exclusive; negative start rejected
Reduce, ForEach, ToRecord, SortCollection Complete synchronously
Concat Arrays/collections copied immediately; general enumerables lazy
FilterAsync, ConcatAsync, ForEachAsync Synchronous callbacks/work run on Task.Run; complete before await returns
FilterParallel, FilterParallelAsync Complete before return/await; unordered output
ForEachParallel, ForEachParallelAsync Concurrent callbacks; caller must synchronize shared mutable state
SortCollectionParallel Sorted output; equal-key order unspecified; small inputs may sort sequentially
ToDictionaryParallel Concurrent callbacks; duplicate-key winner unspecified; returns a ConcurrentDictionary through IDictionary

Both indexed and non-indexed callbacks are supported for ordinary transformations. Map supports different input/output types. ToRecord rejects duplicate keys. Sorts preserve source contents and are not stable for equal keys. Selectors should be pure.

Async callbacks remain synchronous delegates: these methods are CPU offloading helpers, not async-I/O pipelines. Do not pass async-void lambdas. Use native async APIs for I/O and async streams. Cancellation is cooperative; running callbacks cannot be forcibly interrupted. Parallel options are copied, not mutated; either supplied token can cancel the operation. Default maximum parallelism is five.

The legacy void CollectionIterableAsync.ForeachParallel overloads remain but are obsolete. Use ForEachParallelAsync and await it to observe completion and errors.

Migration from 1.0.2

  • Rebuild consumers: Map now uses <TSource,TResult>. Inferred calls such as .Map(x => x + 1) remain valid. Explicit .Map<int>(...) becomes .Map<int,int>(...) or omits type arguments.
  • FilterAsync and general-enumerable ConcatAsync now materialize before completing; work/errors no longer wait until result enumeration. This changes timing and memory lifetime.
  • Registered parallel cancellation raises OperationCanceledException directly instead of the previous manual-check AggregateException. Callback failures remain observable; dictionary merge/key failures may now surface directly after callback processing.
  • Framework-backed methods use framework argument validation; sorts cache keys and can change comparator exception wrapping, null-key handling and tie order.

Performance and scope

Before/after report includes 150 workloads, repeated timings, allocation tradeoffs, tests and reproduction commands. Gains depend on method/input. Async or parallel execution is not automatically faster. Additional key/batch buffers trade memory for speed.

This is an in-memory IEnumerable library, not a replacement for all LINQ. Results can be chained with LINQ. Use Queryable directly for database expression trees to retain provider translation.

dotnet test Performance/Tests/Tests.csproj -c Release
DOTNET_TieredCompilation=0 dotnet run --project Performance/Benchmarks.csproj -c Release

MIT license; see LICENSE.

Product 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.

Version Downloads Last Updated
2.0.3 136 9/21/2026
2.0.2 105 9/21/2026
2.0.1 101 9/21/2026
2.0.0 100 9/21/2026
2.0.0-preview.1 80 9/21/2026
1.0.2 388 12/23/2023
1.0.1 246 12/23/2023
1.0.0 229 12/23/2023