Last active
February 4, 2023 08:45
-
-
Save savaged/69b2e42c41b03d1fd2aadd4e78080640 to your computer and use it in GitHub Desktop.
Demonstrating that the equivalent to the Haskell map function in C# is the Select in Linq
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
/* | |
* Trying to emulate the following Haskell, with the aim of demonstrating | |
* that the map function in C# is the Select in Linq... | |
* | |
* main = do | |
* print (reverseEach ["map", "select"]) | |
* | |
* reverseEach l = map reverse l | |
* | |
*/ | |
Console.WriteLine(ReverseEach(new List<string> { "map", "select" })); | |
string ReverseEach(IEnumerable<string> l) => | |
l.Select(s => s.Reverse()).Aggregate((a, b) => $"{a} {b}"); | |
static class StringEx | |
{ | |
public static string Reverse(this string s) => new string(s.ToCharArray().Reverse().ToArray()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment