Frontmatec.Linq
1.0.4
dotnet add package Frontmatec.Linq --version 1.0.4
NuGet\Install-Package Frontmatec.Linq -Version 1.0.4
<PackageReference Include="Frontmatec.Linq" Version="1.0.4" />
paket add Frontmatec.Linq --version 1.0.4
#r "nuget: Frontmatec.Linq, 1.0.4"
// Install Frontmatec.Linq as a Cake Addin #addin nuget:?package=Frontmatec.Linq&version=1.0.4 // Install Frontmatec.Linq as a Cake Tool #tool nuget:?package=Frontmatec.Linq&version=1.0.4
Frontmatec.Linq
ForEach
Performs the specified action on each element of the sequence.
IsSingle
Determines whether the 'source' contains exactly one element.
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|------------------------ |-----------------:|---------------:|----------------:|-------:|----------:|
| EnumerableIsSingleCheck | 36.047 ns | 0.7604 ns | 1.9492 ns | 0.0172 | 72 B |
| EnumerableCountCheck | 1,980,981.136 ns | 39,473.5803 ns | 104,678.3429 ns | - | 6 B |
| ListIsSingleCheck | 5.989 ns | 0.1412 ns | 0.2280 ns | - | - |
| ListCountCheck | 7.008 ns | 0.1774 ns | 0.2306 ns | - | - |
MergeSorted
Merges two sorted sequences into a single sorted sequence.
var first = new List<int> { 1, 4, 7 };
var second = new List<int> { 2, 5, 8 };
var merged = first.MergeSorted(second, (a, b) => a <= b ? -1 : 1);
| first: 1 4 7
| second: 2 5 8
|------------------
| merged: 12 45 78
Flatten Method
The FlattenTree
method is an extension method for IEnumerable<T>
that flattens a tree of elements into a flat sequence. It supports both depth-first and breadth-first traversal orders.
Usage
Given the following tree:
1
/ \
2 3
/ \
4 5
Depth-First Traversal
Depth-first traversal processes each node and its children before moving on to the next sibling node. This is the default traversal order.
var result = collection.FlattenTree(x => x.Children); // [1, 2, 4, 5, 3]
var result = collection.FlattenTree(x => x.Children, TraversalOrder.DepthFirst); // [1, 2, 4, 5, 3]
Breadth-First Traversal
Breadth-first traversal processes all nodes at the current level before moving on to the next level.
var result = collection.FlattenTree(x => x.Children, TraversalOrder.BreadthFirst); // [1, 2, 3, 4, 5]
Benchmarking
If you have an idea for a faster or better implementation, then replace the 'FlattenContender' method with your own implementation and run the benchmarks ('dotnet run -c release' in terminal for the Frontmatec.Linq.Tests project).
Current benchmark as of 10/02/2025:
| Method | NodeCount | Mean | Error | StdDev | Gen0 | Allocated |
|-------------------------------------------------- |---------- |----------:|----------:|----------:|-------:|----------:|
| FlattenTree_SingleCollection_BreadthFirst | 10 | 1.256 ns | 0.0474 ns | 0.0466 ns | - | - |
| FlattenTree_MultipleCollections_BreadthFirst | 10 | 1.184 ns | 0.0304 ns | 0.0285 ns | - | - |
| FlattenTree_SingleCollection_DepthFirst | 10 | 1.246 ns | 0.0326 ns | 0.0304 ns | - | - |
| FlattenTree_MultipleCollections_DepthFirst | 10 | 1.288 ns | 0.0475 ns | 0.0584 ns | - | - |
| FlattenContender_SingleCollection_DepthFirst | 10 | 7.972 ns | 0.1769 ns | 0.1655 ns | 0.0056 | 88 B |
| FlattenContender_MultipleCollections_DepthFirst | 10 | 8.807 ns | 0.0958 ns | 0.0849 ns | 0.0056 | 88 B |
| FlattenContender_SingleCollection_BreadthFirst | 10 | 11.952 ns | 0.1037 ns | 0.0970 ns | 0.0107 | 168 B |
| FlattenContender_MultipleCollections_BreadthFirst | 10 | 11.630 ns | 0.1337 ns | 0.1251 ns | 0.0107 | 168 B |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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 is compatible. 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. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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.