Skip to content

Commit 653af8b

Browse files
committed
Merge pull request #9905 from bicycle1885/push-associative
Push `Pair`s to `Associative`
2 parents 747fef2 + 20138be commit 653af8b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,6 @@ const base64 = base64encode
276276

277277
@deprecate map!(f::Callable, dest::StridedArray, A::StridedArray, B::Number) broadcast!(f, dest, A, B)
278278
@deprecate map!(f::Callable, dest::StridedArray, A::Number, B::StridedArray) broadcast!(f, dest, A, B)
279+
280+
#9295
281+
@deprecate push!(t::Associative, key, v) setindex!(t, v, key)

base/dict.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ end
246246
getindex(t::Associative, k1, k2, ks...) = getindex(t, tuple(k1,k2,ks...))
247247
setindex!(t::Associative, v, k1, k2, ks...) = setindex!(t, v, tuple(k1,k2,ks...))
248248

249-
push!(t::Associative, key, v) = setindex!(t, v, key)
249+
push!(t::Associative, p::Pair) = setindex!(t, p.second, p.first)
250+
push!(t::Associative, p::Pair, q::Pair) = push!(push!(t, p), q)
251+
push!(t::Associative, p::Pair, q::Pair, r::Pair...) = push!(push!(push!(t, p), q), r...)
250252

251253
# hashing objects by identity
252254

test/dict.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,18 @@ let
269269
b = Dict("フー" => 17, "バー" => 4711)
270270
@test is(typeof(merge(a, b)), Dict{UTF8String,Float64})
271271
end
272+
273+
# issue 9295
274+
let
275+
d = Dict()
276+
@test is(push!(d, 'a' => 1), d)
277+
@test d['a'] == 1
278+
@test is(push!(d, 'b' => 2, 'c' => 3), d)
279+
@test d['b'] == 2
280+
@test d['c'] == 3
281+
@test is(push!(d, 'd' => 4, 'e' => 5, 'f' => 6), d)
282+
@test d['d'] == 4
283+
@test d['e'] == 5
284+
@test d['f'] == 6
285+
@test length(d) == 6
286+
end

0 commit comments

Comments
 (0)