Pipe4Net 1.4.0

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

// Install Pipe4Net as a Cake Tool
#tool nuget:?package=Pipe4Net&version=1.4.0                

Pipe.Net

Inspired by PowerShell, two extension methods that will simplify your code, Pipe and PipeWith

Package manager: Install-Package Pipe4Net

.NET CLI: dotnet add package Pipe4Net


-- Update 16.10.2018 v1.3

For better redability added:

PipeResultTo same as Pipe

EndWith same as PipeWith

added new extension method on int : GenerateForLoopWithIndex((i) ⇒ cw(i)) where i is the current index in for loop, zero based! runs from i = 0 to i < targetInt


var result = IncrementA(IncrementB(IncrementC(1)))

becomes

var pipedResult2 = IncrementC(1).Pipe(IncrementB).Pipe(IncrementA);


You will find another goodie in there , an Option<T> monad in case you need it.


Two useful extension methods on bool type:

.IfTrue(doThis)
.Else(doThis)

Ex: ReturnBoolValue().IfTrue(() => Console.WriteLine("True")).Else(() => Console.WriteLine("False"));

No need for temp variables or { } block statements


The code is pretty simple, i encourage you to play and extend it by your own needs

public static class PipeIt
{
    public static void PipeWith<T>(this T obj, Action<T> action) => action(obj);
  
    public static T Pipe<T>(this T obj, Func<T, T> func) => func(obj);

    public static Option<TR> Pipe<T,TR>(this T obj, Func<T, Option<TR>> func) => func(obj);
}

This is the main reason why this package exists. Look at the other tests also they are pretty intuitive

[Fact]
    public void Should_Have_Same_Result_When_Piped()
    {
        var result = IncrementA(IncrementB(IncrementC(1)));

        var pipedResult = 1.Pipe(IncrementC).Pipe(IncrementB).Pipe(IncrementC);

        Assert.Equal(result,pipedResult);

        var pipedResult2 = IncrementC(1).Pipe(IncrementB).Pipe(IncrementA);

        Assert.Equal(result, pipedResult2);
    }

    private int IncrementA(int val) => val++;

    private int IncrementB(int val) => val++;

    private int IncrementC(int val) => val++;
    

The test above perfectly represents what i want to achieve with this nuget package, i have reading code from right to left, or naming temporary variables, it just one of those things that bothers me in programming, and i think this way or writing code is more elegant:

var result = IncrementA(IncrementB(IncrementC(1))) becomes var pipedResult2 = IncrementC(1).Pipe(IncrementB).Pipe(IncrementA);

Awesome


Some extensions methods on arrays that will make your code easier to read:

  • .ForEach implementation for arrays
  • .DeepCopy
  • .ShallowCopy
  • .AreSameByValue
  • .AreSameByReference
  • .AreSameByValueAndIndex
  • .RemoveElements
  • .RemoveElement
  • .AddElements
  • .AddElement
  • .RemoveNulls
  • .ForEachWithIndex
  • .Split

One extension method on int:

  • .GenerateForLoop
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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
1.4.0 742 3/8/2019
1.3.0 724 10/16/2018
1.2.1 823 8/15/2018
1.2.0 805 8/12/2018
1.1.5 822 8/11/2018
1.1.4 819 8/10/2018
1.1.3 767 8/8/2018
1.1.2 781 8/8/2018
1.1.0 829 8/8/2018
1.0.0 795 8/2/2018