Add Range overlap and set operations#17081
Open
mamantoha wants to merge 13 commits into
Open
Conversation
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
jgaskins
reviewed
Jun 27, 2026
jgaskins
left a comment
Contributor
There was a problem hiding this comment.
I really like the simplicity here. A couple minor notes and a fix for the failing spec, but this is really good. I ran a simple benchmark and both union and overlaps? execute in 1ns on my machine.
| end | ||
| end | ||
|
|
||
| private def adjacent_to?(other : Range) : Bool |
Contributor
There was a problem hiding this comment.
How bad an idea would it be to make this method public?
Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR continues the work from #15106.
Compared to that earlier PR, this version covers the edge cases raised in review comments: open-ended ranges, generic endpoint types, endpoint exclusivity, and adjacent discrete ranges using
succ/pred.It also keeps the
nilreturn behavior for cases whereunioncannot produce a single continuous range orintersectionhas no overlap.Fixes #14487
Fixes #14488
Fixes #10148