Skip to content

Commit

Permalink
Merge pull request #26980 from JuliaLang/mb/deprecate-set-map
Browse files Browse the repository at this point in the history
Deprecate map(f, ::AbstractSet)
  • Loading branch information
Keno authored May 4, 2018
2 parents 429a885 + a6c4691 commit 55a47e8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ Deprecated or removed
* `map` on dictionaries previously operated on `key=>value` pairs. This behavior is deprecated,
and in the future `map` will operate only on values ([#5794]).

* `map` on sets previously returned a `Set`, possibly changing the order or number of elements. This
behavior is deprecated and in the future `map` will preserve order and number of elements ([#26980]).

* Previously, broadcast defaulted to treating its arguments as scalars if they were not
arrays. This behavior is deprecated, and in the future `broadcast` will default to
iterating over all its arguments. Wrap arguments you wish to be treated as scalars with
Expand Down
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ function map!(f::F, dest::AbstractArray, A::AbstractArray) where F
end

# map on collections
map(f, A::Union{AbstractArray,AbstractSet}) = collect_similar(A, Generator(f,A))
map(f, A::AbstractArray) = collect_similar(A, Generator(f,A))

# default to returning an Array for `map` on general iterators
"""
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ import .Iterators.enumerate

# issue #5794
@deprecate map(f, d::T) where {T<:AbstractDict} T( f(p) for p in pairs(d) )
# issue #26359 - map over sets
@deprecate map(f, s::AbstractSet) Set( f(v) for v in s )

# issue #17086
@deprecate isleaftype isconcretetype
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Random/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ let b = ['0':'9';'A':'Z';'a':'z']
if eltype(c) == Char
@test issubset(s, c)
else # UInt8
@test issubset(s, map(Char, c))
@test issubset(s, Set(Char(v) for v in c))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ end
@test i isa AbstractSet
@test i == Set([1])
end
@test map(string, keys(d)) == Set(["1","3"])
@test Set(string(k) for k in keys(d)) == Set(["1","3"])
end

@testset "find" begin
Expand Down

0 comments on commit 55a47e8

Please sign in to comment.