-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnionAll, IntersectAll, ExceptAll #124
Comments
There is Concat, which is the same as SQL UNION ALL. ExceptAll would be "left join where right hand is null", and IntersectAll woul be the same as "inner join, discard right hand side". But neither of these options expresses the intent clearly. |
I agree that a standard UnionAll is redundant with Concat. As for ExceptAll and IntersectAll being expressible with the help of Join, this is true, but as you mentioned, it does not express the intent clearly and LINQ Joins are very wordy to start with. Several LINQ functions can also be reduced to others, like Last() to Skip(Math.Min(0, Count()-2)).Take(1), or Any(predicate) to Where(predicate).Count() > 1. Clarity of intent is a great way to eliminate errors before they happen. Additionally I think there is room for ExcepAllBy, IntersectAllBy, and UnionAllBy variations, and the expressions that these could be reduced to (if in fact they can without semantic differences) would be a lot more complicated. |
Hi, Has the newest library has this function yet ? I have read through all but see nowhere. Thank you. |
LINQ's built-in "Union", "Except" and "Intersect" are somewhat odd among LINQ operators, as most others deal simply with enumerable collections, while these three treat enumerables as proper mathematical sets. Although this nicely mirrors SQL's Union, Intersect, and Except, LINQ does not provide an alternative like SQL's "All" keyword that will allow duplicate elements to be returned.
A working implementation can be found here: http://www.siepman.nl/blog/post/2013/08/19/Except-intersect-and-union-without-distinct.aspx
They could possibly also be implemented as overloads of the existing set operators, but with an optional boolean argument that can toggle "normal" distinct results vs "all" duplicate results.
Example method signature:
public static IEnumerable Union(this IEnumerable first, IEnumerable second, bool all = false);
This would return the results of first.Union(second) if (all == false) and all duplicates in the result if (all == true).
These operators could also be combined with MoreLINQ's ExceptBy (and prospecitve IntersectBy, see #63 ).
I have found using an ExceptByAll type method essential for checking a DataColumn for duplicate values, and reporting back the row numbers of those duplicates.
The text was updated successfully, but these errors were encountered: