Codibre.EnumerableExtensions.Branching 0.3.2

dotnet add package Codibre.EnumerableExtensions.Branching --version 0.3.2                
NuGet\Install-Package Codibre.EnumerableExtensions.Branching -Version 0.3.2                
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="Codibre.EnumerableExtensions.Branching" Version="0.3.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Codibre.EnumerableExtensions.Branching --version 0.3.2                
#r "nuget: Codibre.EnumerableExtensions.Branching, 0.3.2"                
#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.
// Install Codibre.EnumerableExtensions.Branching as a Cake Addin
#addin nuget:?package=Codibre.EnumerableExtensions.Branching&version=0.3.2

// Install Codibre.EnumerableExtensions.Branching as a Cake Tool
#tool nuget:?package=Codibre.EnumerableExtensions.Branching&version=0.3.2                

Actions Status Actions Status Actions Status Maintainability Test Coverage

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.3.2 72 11/18/2024
0.3.1 68 11/16/2024
0.3.0 63 11/16/2024
0.2.0 68 11/15/2024
0.1.4 65 11/15/2024
0.1.3 68 11/15/2024
0.1.2 83 11/11/2024
0.1.1 69 11/11/2024
0.1.0 71 11/11/2024