The source to try as LINQPad program (sorry for one-liner):
void Main(){ var l = new[]{new []{1,2,3},new []{4,5,6}}; var res1 = l.SelectMany(s => s.Select(i => i+1)); res1.Dump(); var res2 = l.MySelectMany(s => s.Select(i => i+1)); res2.Dump();}public static class myExtensions{ public static IEnumerable<TResult> MySelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector){ return source.Aggregate(Enumerable.Empty<TResult>(), (a, s) => a.Concat(selector(s))); }}
3 hours ago, JohnAskew wrote
This article is by Bart De Smet and is worth a look: http://dotnet.dzone.com/news/linq-folding-left-right-and-th
Here's another nice article about folds in LINQ: http://weblogs.asp.net/podwysocki/archive/2009/02/26/functional-c-fun-with-folds.aspx
Thanks for the links... Matthew there wrote how to make .Concat() with .Aggregate(), so that is ok to use I guess...