Created
January 25, 2022 23:22
-
-
Save lostmsu/6922f6e1f5b4f07c88358e92d6e8b312 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System; | |
| Func<int, int, int> addImpl = (a, b) => a + b; | |
| var add = Infix.Create(addImpl); | |
| Console.WriteLine(41 |add| 1); | |
| public class Infix<T1, T2, TResult> { | |
| public Func<T1, T2, TResult> Op; | |
| public static Infix<T2, TResult> operator | | |
| (T1 arg0, Infix<T1, T2, TResult> op) | |
| => new (arg => op.Op(arg0, arg)); | |
| } | |
| public class Infix<T, TResult> { | |
| public Func<T, TResult> Op {get;} | |
| public Infix(Func<T, TResult> op) { | |
| this.Op = op; | |
| } | |
| public static TResult operator | | |
| (Infix<T, TResult> op, T arg) | |
| => op.Op(arg); | |
| } | |
| public static class Infix { | |
| public static Infix<T1, T2, TResult> Create<T1, T2, TResult>(Func<T1, T2, TResult> op) | |
| => new Infix<T1, T2, TResult>{ Op = op }; | |
| } |
This file contains hidden or 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
| 42 |
This file contains hidden or 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
| { | |
| "version": 1, | |
| "target": "Run", | |
| "mode": "Debug" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment