Last active
September 25, 2021 17:51
-
-
Save palladin/8577661 to your computer and use it in GitHub Desktop.
F# style LINQ programming with tuples
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
public static class EnumerableEx | |
{ | |
public static IEnumerable<R> Select<T1, T2, R>(this IEnumerable<Tuple<T1, T2>> source, Func<T1, T2, R> f) | |
{ | |
return source.Select(t => f(t.Item1, t.Item2)); | |
} | |
} | |
Enumerable.Range(1, 10) | |
.Select(x => Tuple.Create(x, x)) | |
.Select(tuple => tuple.Item1 + tuple.Item2); | |
// F# style | |
Enumerable.Range(1, 10) | |
.Select(x => Tuple.Create(x, x)) | |
.Select((first, second) => first + second); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment