Skip to main content

PartiallyApplied by Jason Bock

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: PartiallyApplied

A way to do partial function application in C#

Author: Jason Bock

NuGet: https://www.nuget.org/packages/PartiallyApplied/

You can find more details at https://github.com/JasonBock/PartiallyApplied/blob/main/docs/Quickstart.md

Source : https://github.com/JasonBock/PartiallyApplied

Original Readme

note

PartiallyApplied

A way to do partial function application in C#.

Overview

You can find this code as a package in NuGet. Once installed, you can use it to do partial function application:

public static class Maths
{
public static int Add(int a, int b) => a + b;
}

public static class Runner
{
public static void Run()
{
var incrementBy3 = Partially.Apply(Maths.Add, 3);
var value = incrementBy3(4);
// value is now equal to 7.
}
}

More details can be found on the Quickstart page. Note that if you build the code locally, you'll need to build in Release mode for the package reference in PartiallyApplied.NuGetHost to resolve correctly (or unload that project from the solution as it's optional and delete nuget.config).

About

note

If you need to curry functions, you can use this package

How to use

Example ( source csproj, source files )

This is the CSharp Project that references PartiallyApplied

<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>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

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));
}

Usefull

Download Example (.NET C# )

Share PartiallyApplied

https://ignatandrei.github.io/RSCG_Examples/v2/docs/PartiallyApplied

In the same category (FunctionalProgramming) - 14 other generators

cachesourcegenerator

dunet

Dusharp

Funcky.DiscriminatedUnion

FunicularSwitch

N.SourceGenerators.UnionTypes

OneOf

polytype

rscg_queryables

RSCG_Utils_Memo

Sera.Union

TypeUtilities

UnionGen

UnionsGenerator