-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Implement Enumerable.Reverse(TSource[]) #107957
Conversation
Note regarding the
|
Note regarding the
|
Well, I tried opening in draft to avoid tagging people until I was sure tests were passing... |
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); | ||
} | ||
|
||
if (source.Length == 0) |
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.
Nit: I would probably just have this method call the existing Reverse
directly, although I see why you might have wanted to avoid a redundant type check.
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.
Yeah, my thought process was "I could just call Reverse
, but it's not like this a complicated method or changing very often, and this is more efficient".
T[] expected = source.ToArray(); | ||
Array.Reverse(expected); | ||
|
||
IEnumerable<T> actual = source.ToArray().Reverse(); |
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.
Does this test exercise the case where source
is empty?
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.
Yes, an empty array is in the input data.
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
@@ -96,6 +96,7 @@ public static void MatchSequencePattern() | |||
nameof(Enumerable.Prepend), | |||
nameof(Enumerable.ToHashSet), | |||
nameof(Enumerable.TryGetNonEnumeratedCount), | |||
nameof(Enumerable.Reverse), |
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 wish there was a simple way to distinguish between the different overloads, but I suppose this should suffice.
Closes #107723.