Skip to content

Commit

Permalink
Merge pull request #18727 from ninjin/nin/setconv
Browse files Browse the repository at this point in the history
RFC: Set to Set conversions
  • Loading branch information
JeffBezanson committed Sep 30, 2016
2 parents f935a50 + 3cf83c3 commit 862fb74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 862fb74

Please sign in to comment.