Skip to content
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

Merged
merged 4 commits into from
Sep 25, 2024
Merged

Conversation

333fred
Copy link
Member

@333fred 333fred commented Sep 17, 2024

Closes #107723.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@333fred
Copy link
Member Author

333fred commented Sep 17, 2024

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)
Copy link
Member

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.

Copy link
Member Author

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();
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@333fred 333fred marked this pull request as ready for review September 19, 2024 18:42
@@ -96,6 +96,7 @@ public static void MatchSequencePattern()
nameof(Enumerable.Prepend),
nameof(Enumerable.ToHashSet),
nameof(Enumerable.TryGetNonEnumeratedCount),
nameof(Enumerable.Reverse),
Copy link
Member

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.

@333fred 333fred merged commit d6ac24c into main Sep 25, 2024
83 of 85 checks passed
@333fred 333fred deleted the work/333fred/enumerable.reverse branch September 25, 2024 17:18
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Enumerable.Reverse<T>(T[])
2 participants