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

Added support for passing Range as a parameter to .Exclude. #619

Merged
merged 15 commits into from
Feb 22, 2024
Merged

Added support for passing Range as a parameter to .Exclude. #619

merged 15 commits into from
Feb 22, 2024

Conversation

tacosontitan
Copy link
Collaborator

@tacosontitan tacosontitan commented Feb 5, 2024

TL;DR

This PR resolves #10 by adding support for passing Range as a parameter to .Exclude:

var samples = Enumerable.Range(1, 100).Exclude(6..94);
foreach (var sample in samples)
    Console.WriteLine(sample);

The expected output for the above snippet is 1 - 5 followed by 95 - 100 with each value on its own line.

Format Adjustment

The existing ternary expressions for the Count properties did not match what was present in other methods in the file. As the other formats are generally cleaner I updated the Count properties to break nesting out:

var sample = foo.Bar
    ? foo.Bar
    : foo.Bar < 5
        ? foo.Fizz
        : foo.Buzz;

Improved Documentation

Methods with access levels of protected or higher should have some form of documentation, even if their containing models are private, simply for consumer understanding. As such, I added documentation to the Count properties, and specified that documentation should be inherited from IEnumerable<T> where applicable.

##Constructor Visibility

I marked the constructors for the private types as internal since by definition they'll never be consumed outside of the assembly.

@tacosontitan tacosontitan changed the title Features/range exclude Added support for passing Range as a parameter to .Exclude. Feb 5, 2024
Copy link
Owner

@viceroypenguin viceroypenguin left a comment

Choose a reason for hiding this comment

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

One thing I note in all three implementations is that they assume that !range.Start.IsFromEnd and !range.End.IsFromEnd.

Thankfully, Collection and List patterns are easy, because Index.GetOffset(int length) exists specifically for this purpose. You can filter both range.Start and range.End through this method in the constructor before using them for the rest of the iterator.

For the Core method, it will require some additional evaluation. You can review the Insert for a glimpse at that pattern that will be required to handle it properly.

Source/SuperLinq/Exclude.cs Show resolved Hide resolved
Source/SuperLinq/Exclude.cs Outdated Show resolved Hide resolved
@tacosontitan
Copy link
Collaborator Author

tacosontitan commented Feb 6, 2024

One thing I note in all three implementations is that they assume that !range.Start.IsFromEnd and !range.End.IsFromEnd.

Still looking into this, just haven't had much time this week yet.

@tacosontitan tacosontitan marked this pull request as draft February 8, 2024 23:27
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (886ca78) 95.28% compared to head (21a27bb) 95.27%.

Files Patch % Lines
Source/SuperLinq/Exclude.cs 97.05% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #619      +/-   ##
==========================================
- Coverage   95.28%   95.27%   -0.01%     
==========================================
  Files         248      248              
  Lines        8648     8701      +53     
  Branches     1592     1609      +17     
==========================================
+ Hits         8240     8290      +50     
- Misses        217      219       +2     
- Partials      191      192       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tacosontitan
Copy link
Collaborator Author

I still need to add perf improvements and test coverage.

@tacosontitan
Copy link
Collaborator Author

I will have some time this weekend to work on this assuming I'm not still sick. I appreciate your patience with me and your assistance on it!

# Conflicts:
#	Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt
#	Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt
#	Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt
#	Source/SuperLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt
#	Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt
@viceroypenguin viceroypenguin marked this pull request as ready for review February 22, 2024 19:04
@viceroypenguin viceroypenguin enabled auto-merge (squash) February 22, 2024 19:35
@viceroypenguin viceroypenguin merged commit 635691e into viceroypenguin:master Feb 22, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Exclude() overload that takes a Range
2 participants