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

deprecate behavior of map on dicts. part of #5794 #23648

Merged
merged 1 commit into from
Sep 10, 2017
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------

Expand Down
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down