Skip to content

Commit

Permalink
deprecate behavior of map on dicts. part of #5794 (#23648)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Sep 10, 2017
1 parent 8c2fc37 commit 96f64ce
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
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

0 comments on commit 96f64ce

Please sign in to comment.