Skip to content

Commit d13b0fa

Browse files
SimonDanischararslan
authored andcommitted
add Base.extrema (#24)
1 parent 56e1d8e commit d13b0fa

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

src/IntervalSets.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module IntervalSets
55
# package code goes here
66

77
using Base: @pure
8-
import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, union, intersect, minimum, maximum, range
8+
import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, union, intersect, minimum, maximum, extrema, range
99
if isdefined(Main, :)
1010
import Base:
1111
end

src/closed.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ hash(I::ClosedInterval, h::UInt) = hash(I.left, hash(I.right, hash(_closed_inter
5656

5757
minimum(I::ClosedInterval) = I.left
5858
maximum(I::ClosedInterval) = I.right
59+
extrema(I::ClosedInterval) = (minimum(I), maximum(I))
5960

6061
function intersect(A::ClosedInterval, B::ClosedInterval)
6162
left = max(A.left, B.left)
@@ -105,4 +106,3 @@ end
105106
range{I<:Integer}(i::ClosedInterval{I}) = convert(UnitRange{I}, i)
106107

107108
Base.promote_rule{T1,T2}(::Type{ClosedInterval{T1}}, ::Type{ClosedInterval{T2}}) = ClosedInterval{promote_type(T1, T2)}
108-

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ using Base.Test
4646

4747
@test maximum(I) === 3
4848
@test minimum(I) === 0
49+
@test extrema(I) === (0, 3)
4950

5051
@test 2 in I
5152
@test 1..2 in 0.5..2.5

0 commit comments

Comments
 (0)