Created
February 22, 2012 14:53
-
-
Save ldaniel/1885424 to your computer and use it in GitHub Desktop.
Elegância e/ou deselegância
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
// 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