Created
March 25, 2023 17:18
-
-
Save savaged/4e711bd3c545f68f01a89ed2e910ebc0 to your computer and use it in GitHub Desktop.
Fun tasting curry in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See Computerphile: https://youtu.be/psmu_VAuiag | |
// add x y = x + y | |
Func<int, int, int> AddTwoParameters = (x, y) => x + y; | |
// map (add 100) [1..10] | |
Enumerable.Range(1, 10) | |
.Select(i => AddTwoParameters.AddLater()(100)(i)) | |
.ToList() | |
.ForEach(i => Console.WriteLine(i)); | |
static class Curry | |
{ | |
// add = \x -> (\y -> x + y) | |
public static Func<TInput1, Func<TInput2, TOutput>> AddLater<TInput1, TInput2, TOutput>( | |
this Func<TInput1, TInput2, TOutput> f) | |
=> x => y => f(x, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or just...
dotnet add package Curryfy
See https://github.com/leandromoh/Curryfy