SelectMany and Flatten

2012-03-01 Thread Greg Keogh
Just a Friday morning heads up. Last night I had to search through a collection of object collections, and knew I wanted a flatten operator like Mathematica and other languages have, but couldn't find one. I started coding LINQ Aggregate with Concat and creating a LISP-like clever mess. I thought

Re: SelectMany and Flatten

2012-03-01 Thread David Burela
I only discovered that one myself a few weeks ago while studying for my final MCPD exam. Had no idea that it existed, but now it makes so much sense that it does. Thanks for sharing it Greg! -David Burela On 2 March 2012 09:29, Greg Keogh g...@mira.net wrote: Just a Friday morning heads up.

Re: SelectMany and Flatten

2012-03-01 Thread Michael Minutillo
I think this translates into from p in ParentColl from c in p.ChildColl where c.Type == Foo select c; which I think makes it easier to visualize what is going on (also, you can add more froms in easily Michael M. Minutillo Indiscriminate Information Sponge http://codermike.com On Fri, Mar 2,

FW: SelectMany and Flatten (correction)

2012-03-01 Thread Greg Keogh
Ooops, my original code is correct, but I typed this in the post: ParentColl.SelectMany(p = p.ChildColl).Where(c = c.Type == Foo); I meant: ParentColl.SelectMany(p = p.ChildColl.Where(c = c.Type == Foo)); They produce the same result. The first would select all children before

Re: FW: SelectMany and Flatten (correction)

2012-03-01 Thread Michael Minutillo
It should be the same. SelectMany boils down to IEnumerableTChild SelectManyTParent, TChild(this IEnumerableTParent parents, FuncTParent, IEnumerableTChild selector) { foreach(var parent in parents) foreach(var child in selector(parent)) yield return child; } In the first case