SCurry 1.3.1

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

// Install SCurry as a Cake Tool
#tool nuget:?package=SCurry&version=1.3.1                

Currying C# functions and actions

If you are here, you probably know what Curry and Partial Application are. This library contains extensions for all standard Func<> and Action<> delegates.

Build status codecov NuGet Badge

Features

  1. Supports all standard Func<> and Action<> delegates.
  2. Currying and uncurrying.
  3. Partial Application with special spacer.
  4. Pipe and Compose helper functions.
  5. All code is auto generated and covered by unit tests.
  6. .NET Standard 1.0+, .NET Standard 2.0+.
  7. No external dependencies.

Examples

Lets say you have the next function:

Func<int, int, int, int> Multiply = (a, b, c) => a * b * c;

Partial Application

The library contains Partial Application extensions for all standard delegates:

Func<int, int, int> multiply2Partial = Multiply.Partial(2, 3);
int result = multiply2Partial(4); // 24

In case if you know the values for some arguments in advance you can use the spacer:

using static SCurry.Spacer;
...
Func<int, int, int> multiply2Partial = Multiply.Partial(_, _, 2); // or Multiply.Partial(1, _, 2) or Multiply.Partial(_, 2)
int result = multiply2Partial(3, 4); // 24

At the moment you can use the spacer for delegates with up to 8 parameters. Making it more makes the library ridiculous big.

If you need to make partial call on a function with more that 8 parameters you can combine two Partial functions:

var partial = Add16.Partial(1, 2, 3, 4, 5, 6, 7, 8).Partial(_, 8, 7, 6, 5, 4, 3, 2);
var result = partial(1); // 72

Curry

To curry use Curry extension:

Func<int, Func<int, Func<int, int>>> multiplyCurried = Multiply.Curry();
int result = multiplyCurried(2)(3)(4); // 24

You can combine it with gapped version of Partial extension to get more flexibility:

using static SCurry.Spacer;
...
Func<int, int> multiply2 = Multiply.Partial(_, _, 2).Curry();
int result = multiply6(5)(6); // 30

Uncurry

After curry you may want to get normal function back:

Func<int, int> multiply2curryed = Multiply.Partial(_, _, 2).Curry();
Func<int, int, int> multiply2 = multiply2curryed.Uncurry();
int result = multiply2(3, 4); // 24

Pipe and Compose

You can chain functions with Pipe helper:

using static SCurry.Piper;
...
Func<int, int, int, int> Multiply = (a, b, c) => a * b * c;
Func<int, int> CurryedAdd2WithGap = TestFunctions.Add2.Partial(_, 2).Curry();
Func<int, Func<int, int>> CurryedPartialMultiplyBy3 = Multiply.Partial(_, _, 3).Curry();
Func<int, Func<int, Func<int, int>>> CurryedAdd3 = TestFunctions.Add3.Curry();

var piped = Pipe(
    CurryedAdd2WithGap,
    CurryedPartialMultiplyBy3(1),
    CurryedAdd3(3)(1)
);

var result = piped(0); // 10

Or Compose them to evaluate functions in reverse order:

using static SCurry.Composer;
...
var piped = Compose(
    CurryedAdd2WithGap,
    CurryedPartialMultiplyBy3(1),
    CurryedAdd3(3)(1)
);

var result = piped(0); // 14
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 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 1.0

  • .NETStandard 2.0

    • No dependencies.
  • net5.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.3.1 557 4/4/2021
1.2.0 7,957 5/24/2020
1.1.1 582 5/23/2020
1.1.0 41,934 10/30/2018
1.0.0 703 10/29/2018