Skip to content

Commit 29998c5

Browse files
authored
Merge pull request #13 from JuliaMath/teh/ranges2
Support conversion of AbstractInterval{<:Integer} to AbstractUnitRange
2 parents e83b982 + dbc316c commit 29998c5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/IntervalSets.jl

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function convert{I<:AbstractInterval}(::Type{I}, r::Range)
2727
T = eltype(I)
2828
I(convert(T, minimum(r)), convert(T, maximum(r)))
2929
end
30+
function convert{R<:AbstractUnitRange,I<:Integer}(::Type{R}, i::AbstractInterval{I})
31+
R(minimum(i), maximum(i))
32+
end
3033

3134
ordered{T}(a::T, b::T) = ifelse(a < b, (a, b), (b, a))
3235
ordered(a, b) = ordered(promote(a, b)...)

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ using Base.Test
1010
@test_throws ArgumentError :a .. "b"
1111
I = 0..3
1212
@test string(I) == "0..3"
13+
@test convert(UnitRange, I) === 0:3
14+
@test convert(UnitRange{Int16}, I) === Int16(0):Int16(3)
1315
J = 3..2
1416
K = 5..4
1517
L = 3 ± 2

0 commit comments

Comments
 (0)