Skip to content

Instantly share code, notes, and snippets.

@ldaniel
Created February 22, 2012 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldaniel/1885424 to your computer and use it in GitHub Desktop.
Save ldaniel/1885424 to your computer and use it in GitHub Desktop.
Elegância e/ou deselegância
// Menos elegante?!?
private static void Main(string[] args)
{
Func<int, int> fiveTimes = v => v*5;
Func<int, int> halfOf = v => v/2;
Func<int, int> halfOfFiveTimes = v => halfOf(fiveTimes(v));
Console.WriteLine(halfOfFiveTimes(6));
}
// Elegante?!?
private static void Main(string[] args)
{
Func<int, Envelope<int>> fiveTimes = v => new Envelope<int>(v * 5);
Func<int, Envelope<int>> halfOf = v => new Envelope<int>(v / 2);
Func<int, Envelope<int>> halfOfFiveTimes = v => halfOf(v).Bind(fiveTimes);
Console.WriteLine(halfOfFiveTimes(6).Value);
}
// Fonte: http://elemarjr.net/2012/02/14/monads-em-c/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment