MrModest

Monad.cs

Apr 20th, 2021 (edited)
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. public static class Program
  2. {
  3.     public static void Main()
  4.     {
  5.         var x = 5.Bind(Add1)
  6.             .Bind(Times2)
  7.             .Bind(Square);
  8.     }
  9.  
  10.     public static TOutput Bind<TInput, TOutput>(this TInput input, Func<TInput, TOutput> func)
  11.     {
  12.         return func(input);
  13.     }
  14.  
  15.     public int Add1(int x) => x + 1;
  16.  
  17.     public int Times2(int x) => x * 2;
  18.  
  19.     public int Square(int x) => x * x;
  20. }
Add Comment
Please, Sign In to add comment