Skip to content

Conversation

@rfourquet
Copy link
Member

@rfourquet rfourquet commented Jun 4, 2020

It could only handle a couple of pairs, e.g.
ImmutableDict(1=>1, 2=>2, 3=>3) would throw.

The fix is implemented by adding the
ImmutableDict(t::ImmutableDict, pairs...) constructor,
which generalizes ImmutableDict(t::ImmutableDict, pair)
(with some similarity to how push! accepts multiple items
to be pushed).

It could only handle a couple of pairs, e.g.
ImmutableDict(1=>1, 2=>2, 3=>3) would throw.

The fix is implemented by adding the
`ImmutableDict(t::ImmutableDict, pairs...)` constructor,
which generalizes `ImmutableDict(t::ImmutableDict, pair)`
(with some similarity to how `push!` accepts multiple items
to be pushed).
@rfourquet rfourquet added bugfix This change fixes an existing bug collections Data structures holding multiple items, e.g. sets backport 1.5 labels Jun 4, 2020
@KristofferC KristofferC merged commit 162cde1 into master Jun 4, 2020
@KristofferC KristofferC deleted the rf/immudict-ctor branch June 4, 2020 20:49
KristofferC pushed a commit that referenced this pull request Jun 4, 2020
It could only handle a couple of pairs, e.g.
ImmutableDict(1=>1, 2=>2, 3=>3) would throw.

The fix is implemented by adding the
`ImmutableDict(t::ImmutableDict, pairs...)` constructor,
which generalizes `ImmutableDict(t::ImmutableDict, pair)`
(with some similarity to how `push!` accepts multiple items
to be pushed).

(cherry picked from commit 162cde1)
@BenjaminGalliot
Copy link
Contributor

BenjaminGalliot commented Jun 17, 2020

Is there a reason behind the absence (I guess, tell me if I missed it) of an ImmutableDict constructor from a Dict (AbstractDict)? It is pretty near the multiple pairs constructor but could be useful for automatic conversion with function return type, I think.

OrderedDict from DataStructures and Dict from Base implement this constructor too.

Something like ImmutableDict(d::Dict) = ImmutableDict(d...)

@rfourquet
Copy link
Member Author

I don't think there is any reason, besides that this ImmutableDict is not really for public consumption and therefore has mostly only methods needed in Base itself. But it turns out to be a useful type to use also in some packages.

I could have used a ImmutableDict(d) constructor (where d is an iterator) a couple of times but didn't get around to making a PR yet.

@BenjaminGalliot
Copy link
Contributor

BenjaminGalliot commented Jun 17, 2020

That explains why it needs to be imported manually…

Honestly, I bumped into it from here then there because I was searching a good pattern to avoid a lot of tramp data across many functions because of a Dict variable (almost only constants in a hierarchical structure, like database parameters, regexes and paths), so naturally I found the global configuration variable…

simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
It could only handle a couple of pairs, e.g.
ImmutableDict(1=>1, 2=>2, 3=>3) would throw.

The fix is implemented by adding the
`ImmutableDict(t::ImmutableDict, pairs...)` constructor,
which generalizes `ImmutableDict(t::ImmutableDict, pair)`
(with some similarity to how `push!` accepts multiple items
to be pushed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This change fixes an existing bug collections Data structures holding multiple items, e.g. sets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants