Skip to content

Commit d64c971

Browse files
simeonschaubJeffBezanson
authored andcommitted
nicer constructor for ImmutableDict (#34297)
1 parent 270fcff commit d64c971

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

base/dict.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ Create a new entry in the Immutable Dictionary for the key => value pair
749749
ImmutableDict
750750
ImmutableDict(KV::Pair{K,V}) where {K,V} = ImmutableDict{K,V}(KV[1], KV[2])
751751
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair) where {K,V} = ImmutableDict{K,V}(t, KV[1], KV[2])
752+
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(rest...), KV)
752753

753754
function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
754755
key, value = key_value

test/dict.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ import Base.ImmutableDict
709709

710710
@test_throws KeyError d[k1]
711711
@test_throws KeyError d1["key2"]
712+
713+
v = [k1 => v1, k2 => v2]
714+
d5 = ImmutableDict(v...)
715+
@test d5 == d2
716+
@test collect(d5) == v
712717
end
713718

714719
@testset "filtering" begin

0 commit comments

Comments
 (0)