-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Pair to Pair conversions #18736
Conversation
@@ -21,6 +21,7 @@ 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 => 4711) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should test the element types too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using ===
instead of ==
will do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, new version pushed.
@@ -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,C,D}(::Type{Pair{A,B}}, x::Pair{C,D}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be sufficient to declare function convert{A,B}(::Type{Pair{A,B}}, x::Pair)
since you don't use C
or D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, I also added a few additional test to test symmetry between the first and second element.
Stumbled upon this when trying to convert
Pair{SubString,SubString}
intoPair{String,String}
.