Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name = "IntervalSets"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.3.2"
version = "0.4.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
julia = "0.7, 1"
EllipsisNotation = "0.4"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
5 changes: 4 additions & 1 deletion src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Statistics: mean

using Dates

using EllipsisNotation
import EllipsisNotation: Ellipsis

export AbstractInterval, Interval, OpenInterval, ClosedInterval,
⊇, .., ±, ordered, width, duration, leftendpoint, rightendpoint, endpoints,
isclosed, isleftclosed, isrightclosed, isleftopen, isrightopen, closedendpoints,
Expand Down Expand Up @@ -181,7 +184,7 @@ isrightclosed(d::TypedEndpointsInterval{L,:open}) where {L} = false
# The third is the one we want, but the first two are needed to resolve ambiguities
Base.Slice{T}(i::TypedEndpointsInterval{:closed,:closed,I}) where {T<:AbstractUnitRange,I<:Integer} =
Base.Slice{T}(minimum(i):maximum(i))
Base.Slice(i::TypedEndpointsInterval{:closed,:closed,I}) where I<:Integer =
Base.Slice(i::TypedEndpointsInterval{:closed,:closed,I}) where I<:Integer =
Base.Slice(minimum(i):maximum(i))
function Base.OneTo{T}(i::TypedEndpointsInterval{:closed,:closed,I}) where {T<:Integer,I<:Integer}
@noinline throwstart(i) = throw(ArgumentError("smallest element must be 1, got $(minimum(i))"))
Expand Down
7 changes: 6 additions & 1 deletion src/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ convert(::Type{TypedEndpointsInterval{L,R}}, d::Interval{L,R}) where {L,R} = d
iv = l..r

Construct a ClosedInterval `iv` spanning the region from `l` to `r`.

(The symbol `..` is the same as in the package EllipsisNotation.jl.)
"""
..(x, y) = ClosedInterval(x, y)
..

(::Ellipsis)(x, y) = ClosedInterval(x, y)


"""
iv = center±halfwidth
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
struct IncompleteInterval <: AbstractInterval{Int} end

@testset "IntervalSets" begin
@test isempty(detect_ambiguities(IntervalSets, Base, Core))
if VERSION >= v"1.1"
# Julia 1.0 defines getindex(a::GenericArray, i...) in Test,
# which could cause an ambiguity with getindex(A::AbstractArray, ::EllipsisNotation.Ellipsis)
@test isempty(detect_ambiguities(IntervalSets, Base, Core))
end

@test ordered(2, 1) == (1, 2)
@test ordered(1, 2) == (1, 2)
Expand Down