Skip to content
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

Merged
merged 1 commit into from Oct 1, 2016
Merged

RFC: Pair to Pair conversions #18736

merged 1 commit into from Oct 1, 2016

Conversation

ghost
Copy link

@ghost ghost commented Sep 30, 2016

Stumbled upon this when trying to convert Pair{SubString,SubString} into Pair{String,String}.

@@ -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)
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Author

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})
Copy link
Member

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

Copy link
Author

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.

@vchuravy vchuravy merged commit 3398c7e into JuliaLang:master Oct 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants