-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix union and union! of intervals #74
base: master
Are you sure you want to change the base?
Conversation
throw(ArgumentError( | ||
"Cannot `union!` array of intervals of type $T as the type may change" | ||
)) | ||
end |
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.
It would be better to use dispatch here for future interval types can support their own union!
methods
function Base.union!(intervals::AbstractVector{<:AbstractInterval})
throw(ArgumentError("Cannot `union!` array of intervals of type $(eltype(intervals)) as the type may change"))
end
Base.union!(intervals::AbstractVector{<:Union{AbstractInterval,Interval}) = ...
(I think this works)
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.
Doesn't the existing definition already allow that?
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 think my point here was that this approach in the PR isn't the best for new interval types that want to define their own union!
method.
Fixes: #73 |
function Base.union(intervals::AbstractVector{<:AbstractInterval}) | ||
return union!(convert(Vector{AbstractInterval}, intervals)) | ||
function Base.union( | ||
interval::Union{AbstractInterval, AbstractVector{<:AbstractInterval}}, intervals..., |
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.
Should we do:
interval::Union{AbstractInterval, AbstractVector{<:AbstractInterval}}, intervals..., | |
interval::Union{AbstractInterval, AbstractVector{<:AbstractInterval}}, intervals::Union{AbstractInterval, AbstractVector{<:AbstractInterval}}..., |
Avoids a call such as union(Interval(1,2), 3)
causing a confusing error
For the purposes of these definitions, a "set" of intervals is either a single
AbstractInterval
or a vector ofAbstractInterval
s.This now supports the methods that set
union
supports. Notably, the method @morris25 found will now throw anArgumentError
rather than falling back to the Base definition and giving a different result.Fixes #73
Before:
After: