Skip to content

Commit

Permalink
Merge pull request JuliaLang#9905 from bicycle1885/push-associative
Browse files Browse the repository at this point in the history
Push `Pair`s to `Associative`
  • Loading branch information
ivarne committed Jan 24, 2015
2 parents 747fef2 + 20138be commit 653af8b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,6 @@ const base64 = base64encode

@deprecate map!(f::Callable, dest::StridedArray, A::StridedArray, B::Number) broadcast!(f, dest, A, B)
@deprecate map!(f::Callable, dest::StridedArray, A::Number, B::StridedArray) broadcast!(f, dest, A, B)

#9295
@deprecate push!(t::Associative, key, v) setindex!(t, v, key)
4 changes: 3 additions & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ end
getindex(t::Associative, k1, k2, ks...) = getindex(t, tuple(k1,k2,ks...))
setindex!(t::Associative, v, k1, k2, ks...) = setindex!(t, v, tuple(k1,k2,ks...))

push!(t::Associative, key, v) = setindex!(t, v, key)
push!(t::Associative, p::Pair) = setindex!(t, p.second, p.first)
push!(t::Associative, p::Pair, q::Pair) = push!(push!(t, p), q)
push!(t::Associative, p::Pair, q::Pair, r::Pair...) = push!(push!(push!(t, p), q), r...)

# hashing objects by identity

Expand Down
15 changes: 15 additions & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,18 @@ let
b = Dict("フー" => 17, "バー" => 4711)
@test is(typeof(merge(a, b)), Dict{UTF8String,Float64})
end

# issue 9295
let
d = Dict()
@test is(push!(d, 'a' => 1), d)
@test d['a'] == 1
@test is(push!(d, 'b' => 2, 'c' => 3), d)
@test d['b'] == 2
@test d['c'] == 3
@test is(push!(d, 'd' => 4, 'e' => 5, 'f' => 6), d)
@test d['d'] == 4
@test d['e'] == 5
@test d['f'] == 6
@test length(d) == 6
end

0 comments on commit 653af8b

Please sign in to comment.