Suppose, I have an IEnumerable<Tuple<string, object>> and that I want to replace for each element of the enumeration the first element by a list of (several) other elements:
Original enumerable: { { "a", obj1 }, { "b", obj2 } }
First-element replacement: a -> { "c", "d" }, b -> { "e", "f", "g" }
Result : { { "c", obj1 }, { "d", obj1 }, { "e", obj2 }, { "f" , obj2 }, { "g" , obj2 } }
How can I accomplish this with SelectMany in a better way than
enumerable.SelectMany(item => ReplacementFunction(item.Item1).Select(newItem =>
new Tuple<string, object>(newItem, item.Item2)))
Well, I’d probably use a query expression instead:
But that’s basically the same thing…