Skip to content

Commit a6c4691

Browse files
committed
Deprecate map(f, ::AbstractSet)
`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. Fixes #26359.
1 parent fe99c4a commit a6c4691

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,9 @@ Deprecated or removed
959959
* `map` on dictionaries previously operated on `key=>value` pairs. This behavior is deprecated,
960960
and in the future `map` will operate only on values ([#5794]).
961961

962+
* `map` on sets previously returned a `Set`, possibly changing the order or number of elements. This
963+
behavior is deprecated and in the future `map` will preserve order and number of elements ([#26980]).
964+
962965
* Previously, broadcast defaulted to treating its arguments as scalars if they were not
963966
arrays. This behavior is deprecated, and in the future `broadcast` will default to
964967
iterating over all its arguments. Wrap arguments you wish to be treated as scalars with

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ function map!(f::F, dest::AbstractArray, A::AbstractArray) where F
19801980
end
19811981

19821982
# map on collections
1983-
map(f, A::Union{AbstractArray,AbstractSet}) = collect_similar(A, Generator(f,A))
1983+
map(f, A::AbstractArray) = collect_similar(A, Generator(f,A))
19841984

19851985
# default to returning an Array for `map` on general iterators
19861986
"""

base/deprecated.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ import .Iterators.enumerate
576576

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

580582
# issue #17086
581583
@deprecate isleaftype isconcretetype

stdlib/Random/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ let b = ['0':'9';'A':'Z';'a':'z']
609609
if eltype(c) == Char
610610
@test issubset(s, c)
611611
else # UInt8
612-
@test issubset(s, map(Char, c))
612+
@test issubset(s, Set(Char(v) for v in c))
613613
end
614614
end
615615
end

test/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ end
926926
@test i isa AbstractSet
927927
@test i == Set([1])
928928
end
929-
@test map(string, keys(d)) == Set(["1","3"])
929+
@test Set(string(k) for k in keys(d)) == Set(["1","3"])
930930
end
931931

932932
@testset "find" begin

0 commit comments

Comments
 (0)