-
Notifications
You must be signed in to change notification settings - Fork 416
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
Add a ConcatAll<T>(IEnumerable<IEnumerable<T>>) method #556
Comments
ConcatAll<T>(IEnumerable<IEnumerable<T>>)
method
Since, as you said, there's If you think I've misunderstood your value proposition then happy to reconsider. |
@atifaziz It's not just to avoid the lambda. It's to improve readability and make the code much easier to understand. I've had coworkers tell me that they look at This is also similar to |
If readability is the sole problem then it should be solved locally with a single-line aliasing wrapper: public static IEnumerable<T> ConcatAll<T>(this IEnumerable<IEnumerable<T>> source) =>
source.SelectMany(e => e); While we may agree that
To some extent but by that argument alone, you can eventually reduce just about everything in LINQ to
Also something that might not be obvious is the maintainer's dilemma: the trouble of allowing one-liners for purpose of readability means that many such requests will start pouring in and I fear that discussions will end up getting very subjective. The primary objectivity I'd like to maintain is therefore that a suggestion must be operationally intelligent or do some amount of non-trivial work. And even with that, we've struggled with the naming of many operators in MoreLINQ because one name might speak more to some people than another. |
A commonly encountered scenario it to have an
IEnumerable<IEnumerable<T>>
that you wish to combineinto a single
IEnumerable<T>
without any transformations.To do this using only the standard library, you can use
SelectMany
:MoreLINQ provides a
Flatten
method to combine a sequence of arbitrarily nested sequences, but the fact it's not type safe creates even more boilerplate and turns type errors into runtime ones instead of compile time:It would also go down too many levels if
T
happens to implementIEnumerable
, though this is uncommon in my use cases at least.It'd be much easier to read and understand with a
ConcatAll
method:The text was updated successfully, but these errors were encountered: