diff --git a/Project.toml b/Project.toml index 9ef842f..138cabd 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 03734b5..0bfcfd0 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -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, @@ -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))")) diff --git a/src/interval.jl b/src/interval.jl index f97ad7d..9ba0f7e 100644 --- a/src/interval.jl +++ b/src/interval.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a5412df..5b1793c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)