Codibre.EnumerableExtensions.Branching
0.1.4
See the version list below for details.
dotnet add package Codibre.EnumerableExtensions.Branching --version 0.1.4
NuGet\Install-Package Codibre.EnumerableExtensions.Branching -Version 0.1.4
<PackageReference Include="Codibre.EnumerableExtensions.Branching" Version="0.1.4" />
paket add Codibre.EnumerableExtensions.Branching --version 0.1.4
#r "nuget: Codibre.EnumerableExtensions.Branching, 0.1.4"
// Install Codibre.EnumerableExtensions.Branching as a Cake Addin #addin nuget:?package=Codibre.EnumerableExtensions.Branching&version=0.1.4 // Install Codibre.EnumerableExtensions.Branching as a Cake Tool #tool nuget:?package=Codibre.EnumerableExtensions.Branching&version=0.1.4
Codibre.EnumerableExtensions.Branching
Branching operation that allows you to give a single enumerable many different, concurrent resolutions
Why?
In many situations we have a unmaterialized enumerable, and need to use it on several different operations and will need to iterate over it many times. To do it safely, one option is to materialize it into an array and run the operations over it. Another is to manually create a loop that runs all the operations. The first option may result in an unwanted memory consumption, the second one into create a code that ends to be too complex, mixing many responsabilities into a single point just to take advantage of one iteration. This library offers a third option: enumerable branching.
How to use?
First, do all the operations that are commons between the different resolutions you want
var enumerable = baseEnumerable
.Select(DoSomeOperation)
.SelectMany(DoSomeFlatteningOperation)
.Where(DoSomeFilter)
...;
Finally, you ban use the Branch operation to diverge the many resolutions you need
await enumerable
.Branch()
.Add((e) => e.Select(Resolution1).ToArrayAsync(), out var result1)
.Add((e) => e.Select(Resolution2).MinAsync(), out var result2)
.Add((e) => e.Select(Resolution3).MaxAsync(), out var result3)
.Run();
Now, you'll have the three results you need, accesible through the property Value of result1, 2 and 3!
What this operation is doing under the hood?
The first operations run only one time, not one per branch, and then, the iteration continues concurrenctly between the branches informed. This is possible only using async tasks and yielding between them, but some buffer with partial results needs to be done for performance reasons, too, but overall, the Branch operation will try to keep as less memory in use as possible, but trying to keep performance close to what it'd be without it.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- System.Linq.Async (>= 6.0.1)
-
net8.0
- System.Linq.Async (>= 6.0.1)
-
net9.0
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.