System.Tuple: More .NET 4.0 Functional Goodness
In functional languages, tuples are pretty much a requirement. Of the functional languages I’ve used, including Erlang and T-SQL, tuples are bread’n’butter. Every release of .NET has included more and more support for functional programming paradigms, and we’re getting tuple support in the BCL in .NET 4.0, though first-class language support is still not there. Here’s an example of using System.Tuple with the new Zip LINQ operator.
Code Snippet
- var xs = new List<int> { 1, 3, 5 };
- var ys = new List<string> { "hello", "world", "channel" };
- var zs = xs.Zip(ys, Tuple.Create);
- foreach (var z in zs)
- Console.WriteLine("{1}:{0}",z.Item1, z.Item2);