-
Notifications
You must be signed in to change notification settings - Fork 33
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 some Crutches.Range functions. #74
Conversation
Range.overlaps?/2 Takes two ranges, returns true if any elements appear in both ranges. Range.intersection/2 Takes two ranges, returns the intersection (or nil) Range.union/2 Takes two ranges, returns the union (or nil) Reference: mykewould#73 -- Note about dealing with descending ranges: 5..3 as opposed to 3..5 For the purposes of interstions and unions there's really no difference, but the code was bugged. The results of these functions will be ascending ranges (or nil).
Looks good! Props for including specs! Some small points that might require some more discussion:
|
@KNRZ In set theory, that is definitely defined. It might not even be a bad idea to include a type like that if there is a use case for it. I can definitely think of scheduling as an application. Does Elixir have custom iterators or something like Python, so that we can avoid expanding those two ranges into a list if we can avoid it? |
I'm not going to pretend to know the right way to handle the union of two ranges that don't overlap. However, it's possible that this is better handled as a Set function. |
@jdl Not an issue :) To keep you in the loop; the union operation is from set theory. As far as I'm concerned it's up for debate whether we should return If you want a set, then currently you can probably use |
A complex range type seems like overkill until someone actually needs such a thing. |
Thanks for your input! Anyway, this looks good to me, so I'm merging it in. The rest can go on the todo list. |
Added some Crutches.Range functions. Closes #73.
Range.overlaps?/2
Takes two ranges, returns true if any elements appear in both ranges.
Range.intersection/2
Takes two ranges, returns the intersection (or nil)
Range.union/2
Takes two ranges, returns the union (or nil)
Reference: #73
Note about dealing with descending ranges:
5..3 as opposed to 3..5
For the purposes of interstions and unions there's really no
difference, but the code was bugged. The results of these
functions will be ascending ranges (or nil).