Your question aroused my heart of developers, so I raised it again and came up with the following:
public static IEnumerable<T2> Map<T,T2>(this ParallelQuery<T> source, Func<T,T2> func) { var list = new ConcurrentBag<T2>(); source.ForAll(s => list.Add(func(s))); return list.ToList(); }
The ForAll wire passes through the source request in parallel and adds the result to the thread safe collection.
I keep this in mind when I need behavior similar to type, with some kind of personal twist. This can be an efficient approach when the func function is a relatively heavy process.
source share