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: Set to Set conversions #18727

Merged
merged 1 commit into from Sep 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ function hash(s::Set, h::UInt)
end
return h
end

convert{T}(::Type{Set{T}}, s::Set{T}) = s
convert{T,S}(::Type{Set{T}}, x::Set{S}) = Set{T}(x)
16 changes: 16 additions & 0 deletions test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,19 @@ end
@test pop!(Set(1:2), 2, nothing) == 2

@test length(Set(['x',120])) == 2

# convert
let
iset = Set([17, 4711])
cfset = convert(Set{Float64}, iset)
@test typeof(cfset) == Set{Float64}
@test cfset == iset
fset = Set([17.0, 4711.0])
ciset = convert(Set{Int}, fset)
@test typeof(ciset) == Set{Int}
@test ciset == fset
ssset = Set(split("foo bar"))
cssset = convert(Set{String}, ssset)
@test typeof(cssset) == Set{String}
@test cssset == Set(["foo", "bar"])
end