-
Notifications
You must be signed in to change notification settings - Fork 420
Added IndexBy operator #562
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
Conversation
|
@atifaziz on AppVeyor build I am receiving "New code was generated during build that's not been committed." error. I belive that it is about generated extension wrappers. Can you help me please? |
That's correct. You just need to run |
|
Nice. When I tried to run these cmd I got an error and the console closed before I could read. May we follow with the review? |
|
This PR addresses #560. |
|
@atifaziz adjusts done. Except by |
MoreLinq/IndexBy.cs
Outdated
| /// If null, the default equality comparer for <typeparamref name="TSource"/> is used.</param> | ||
| /// <returns>A sequence of unique keys and their number of occurrences in the original sequence.</returns> | ||
|
|
||
| public static IEnumerable<TResult> IndexBy<TSource, TKey, TResult>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like IndexBy is not very descriptive of what this does. Other languages like Ruby have index_by as what C# knows as ToDictionary. I'm having a hard time coming up with a better name. Since this is mostly CountBy, where the last parameter to resultSelector is decremented once, does this really make sense to add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like
IndexByis not very descriptive of what this does. Other languages like Ruby haveindex_byas what C# knows asToDictionary. I'm having a hard time coming up with a better name.
It's consistent with Index, which pairs each element of sequence with its zero-based position in the sequence. IndexBy does the same except the positions are relative to a key group. That's how the name makes sense to me; that it's a variation of Index.
Since this is mostly
CountBy, where the last parameter toresultSelectoris decremented once, does this really make sense to add?
CountBy aggregates on keys. This gives you the source elements in the result so is different enough to be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atifaziz adjusts done.
Thanks 👍
Except by
elements. I did it for consistency,IndexByneed elements,CountBydoes not, butCountByImpldoes not know them, so it always provides.
I understand but now CountBy will pay the price for something not requested by the user, for some internal implementation detail of code sharing. We should resolve this somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like
IndexByis not very descriptive of what this does. Other languages like Ruby haveindex_byas what C# knows asToDictionary. I'm having a hard time coming up with a better name. Since this is mostlyCountBy, where the last parameter toresultSelectoris decremented once, does this really make sense to add?
The fact that you're having trouble with the name got me thinking some more. It seems to me, what we may want to have here in the end is something more general, a ScanBy (perhaps the name you were looking for?) whereby IndexBy wouldn't be needed anymore. It would also enable a whole other set of running (grouped) accumulations. It might also explain why it's odd to have IndexBy piggy-backing on CountBy's implementation.
PS See #563 for the idea.
|
I did a quick spike and implemented |
|
@atifaziz glad you figure out the method benefícits. The implantation looks great. About no materialize entire source, we should add a ‘*DoesNotIterateUnnecessaryElements’ test to assure It. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CountBy implementation changes in this PR should be reverted now that IndexBy uses ScanBy.
we should add a ‘*DoesNotIterateUnnecessaryElements’ test to assure It.
Good idea!
|
@atifaziz adjusts done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I need to review the documentation whenever I have time next.
need help with method summary/readme, please