LINQ: IEnumerable<KeyValuePair<SomeType, IEnumerable<OtherType>>> selection

linq

Solution

I'm unsure if you want the Value in the new KeyValuePair to be an enumerable of that type or a single element. Here's both versions

IEnumerable version

var toReturn = source.Select(x => new KeyValuePair<SomeType,IEnumerable<SomeOtherType>>(x.Key, x.Value.Take(1));

Non-Enumerable Version

var toReturn = source.Select(x => new KeyValuePair<SomeType,SomeOtherType>(x.Key,x.Value.First());

Problem

How do I transform this `IEnumerable<KeyValuePair<MyType, IEnumerable<OtherType>>>` into new sequence of the same type, except I just want `First()` that is in the value (`IEnumerable<OtherType>`). Something like this (pseudo code): ``` var toReturn = from kv in source let k = new KeyValuePair(kv.Key, kv.Value.First()) select k; ```

Original source