diff --git a/base/operators.jl b/base/operators.jl index 6d9dcc66b2df6..9ce58c1f98cf3 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -964,6 +964,11 @@ reverse{A,B}(p::Pair{A,B}) = Pair{B,A}(p.second, p.first) endof(p::Pair) = 2 length(p::Pair) = 2 +convert{A,B}(::Type{Pair{A,B}}, x::Pair{A,B}) = x +function convert{A,B}(::Type{Pair{A,B}}, x::Pair) + convert(A, x[1]) => convert(B, x[2]) +end + # some operators not defined yet global //, >:, <|, hcat, hvcat, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √, ∛ diff --git a/test/operators.jl b/test/operators.jl index f42331f1a0076..49a94b70a5a55 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -21,6 +21,9 @@ B = [true true false] @test reverse(Pair(1,2)) == Pair(2,1) @test reverse(Pair("13","24")) == Pair("24","13") @test typeof(reverse(Pair{String,Int64}("a",1))) == Pair{Int64,String} +@test convert(Pair{Float64,Float64}, 17 => 4711) === (17.0 => 4711.0) +@test convert(Pair{Int,Float64}, 17 => 4711) === (17 => 4711.0) +@test convert(Pair{Float64,Int}, 17 => 4711) === (17.0 => 4711) p = 1=>:foo @test first(p) == 1