Filtering subsets using Linq

Posted by Nathan Matthews on Stack Overflow See other posts from Stack Overflow or by Nathan Matthews
Published on 2010-05-12T08:31:15Z Indexed on 2010/05/12 8:34 UTC
Read the original article Hit count: 205

Filed under:
|
|
|
|

Hi All,

Imagine a have a very long enunumeration, too big to reasonably convert to a list. Imagine also that I want to remove duplicates from the list. Lastly imagine that I know that only a small subset of the initial enumeration could possibly contain duplicates. The last point makes the problem practical.

Basically I want to filter out the list based on some predicate and only call Distinct() on that subset, but also recombine with the enumeration where the predicate returned false.

Can anyone think of a good idiomatic Linq way of doing this? I suppose the question boils down to the following:

With Linq how can you perform selective processing on a predicated enumeration and recombine the result stream with the rejected cases from the predicate?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about predicate