Skip to content

Instantly share code, notes, and snippets.

@palladin
Last active September 25, 2021 17:51
Show Gist options
  • Save palladin/8577661 to your computer and use it in GitHub Desktop.
Save palladin/8577661 to your computer and use it in GitHub Desktop.
F# style LINQ programming with tuples
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