diff --git a/NEWS.md b/NEWS.md index e838a3ed0e800..7b0d6dc390109 100644 --- a/NEWS.md +++ b/NEWS.md @@ -428,6 +428,9 @@ Deprecated or removed * The `Range` abstract type has been renamed to `AbstractRange` ([#23570]). + * `map` on dictionaries previously operated on `key=>value` pairs. This behavior is deprecated, + and in the future `map` will operate only on values ([#5794]). + Command-line option changes --------------------------- diff --git a/base/abstractarray.jl b/base/abstractarray.jl index bf84de4251aad..686ab40ef379e 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1936,7 +1936,7 @@ function map!(f::F, dest::AbstractArray, A::AbstractArray) where F end # map on collections -map(f, A::Union{AbstractArray,AbstractSet,Associative}) = collect_similar(A, Generator(f,A)) +map(f, A::Union{AbstractArray,AbstractSet}) = collect_similar(A, Generator(f,A)) # default to returning an Array for `map` on general iterators """ diff --git a/base/deprecated.jl b/base/deprecated.jl index 65d99d763ac0f..246a06367ab66 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1763,6 +1763,9 @@ import .Iterators.enumerate @deprecate_binding Range AbstractRange +# issue #5794 +@deprecate map(f, d::T) where {T<:Associative} T( f(p) for p in pairs(d) ) + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/test/dict.jl b/test/dict.jl index dbd4771b2dfe1..a37ca0e8142b9 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -429,9 +429,8 @@ d = Dict('a'=>1, 'b'=>1, 'c'=> 3) # generators, similar d = Dict(:a=>"a") -@test @inferred(map(identity, d)) == d -@test @inferred(map(p->p.first=>p.second[1], d)) == Dict(:a=>'a') -@test_throws ArgumentError map(p->p.second, d) +# TODO: restore when 0.7 deprecation is removed +#@test @inferred(map(identity, d)) == d # Issue 12451 @test_throws ArgumentError Dict(0)