RSCG – PartiallyApplied
 
 
| name | PartiallyApplied | 
| nuget | https://www.nuget.org/packages/PartiallyApplied/ | 
| link | https://github.com/JasonBock/PartiallyApplied/blob/main/docs/Quickstart.md | 
| author | Jason Bock | 
If you need to curry functions,you can use this package
This is how you can use PartiallyApplied .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
	<ItemGroup>
    <PackageReference Include="PartiallyApplied" Version="1.3.0" />
  </ItemGroup>
</Project>
The code that you will use is
using System;
namespace PartFunc;
class Program
{
    static void Main(string[] args)
    {
        
        var disc10Percent = Partially.Apply(Accounting.Discount,1/10f);
        Console.WriteLine(disc10Percent(disc10Percent(100)));
        
    }
}
namespace PartFunc;
public class Accounting
{
    public static float Discount( float discount,float price)
    {
        var val= price * (1- discount);
        return val;
    }
}
The code that is generated is
using System;
#nullable enable
public static partial class Partially
{
	public static Func<float,float> Apply(Func<float,float,float> method,float discount) =>
		new((price) => method(discount,price));
}
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/PartiallyApplied
Leave a Reply