Skip to content

Commit

Permalink
nicer constructor for ImmutableDict (#34297)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored and JeffBezanson committed Jan 16, 2020
1 parent 270fcff commit d64c971
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ Create a new entry in the Immutable Dictionary for the key => value pair
ImmutableDict
ImmutableDict(KV::Pair{K,V}) where {K,V} = ImmutableDict{K,V}(KV[1], KV[2])
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair) where {K,V} = ImmutableDict{K,V}(t, KV[1], KV[2])
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(rest...), KV)

function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
key, value = key_value
Expand Down
5 changes: 5 additions & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ import Base.ImmutableDict

@test_throws KeyError d[k1]
@test_throws KeyError d1["key2"]

v = [k1 => v1, k2 => v2]
d5 = ImmutableDict(v...)
@test d5 == d2
@test collect(d5) == v
end

@testset "filtering" begin
Expand Down

0 comments on commit d64c971

Please sign in to comment.