Fix union and union! of intervals - #74
Open
iamed2 wants to merge 1 commit into
Open
Conversation
omus
requested changes
Jun 14, 2019
| throw(ArgumentError( | ||
| "Cannot `union!` array of intervals of type $T as the type may change" | ||
| )) | ||
| end |
Collaborator
There was a problem hiding this comment.
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)
Member
Author
There was a problem hiding this comment.
Doesn't the existing definition already allow that?
Collaborator
There was a problem hiding this comment.
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.
Collaborator
|
Fixes: #73 |
omus
reviewed
Jan 17, 2020
| function Base.union(intervals::AbstractVector{<:AbstractInterval}) | ||
| return union!(convert(Vector{AbstractInterval}, intervals)) | ||
| function Base.union( | ||
| interval::Union{AbstractInterval, AbstractVector{<:AbstractInterval}}, intervals..., |
Collaborator
There was a problem hiding this comment.
Should we do:
Suggested change
| 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
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.
For the purposes of these definitions, a "set" of intervals is either a single
AbstractIntervalor a vector ofAbstractIntervals.This now supports the methods that set
unionsupports. Notably, the method @morris25 found will now throw anArgumentErrorrather than falling back to the Base definition and giving a different result.Fixes #73
Before:
After: