Added recursive merge function for NamedTuple, addresses #29215#29259
Added recursive merge function for NamedTuple, addresses #29215#29259JeffBezanson merged 7 commits intoJuliaLang:masterfrom
Conversation
|
Screwed up the docstring slightly, another commit is on the way (including another simple test, because why not)... |
…st for said merge function
base/namedtuple.jl
Outdated
| """ | ||
| merge(a::NamedTuple, b::NamedTuple...) | ||
|
|
||
| Perform a recursive merge of two or more named tuples. |
There was a problem hiding this comment.
I don't really see this as recursive; maybe we could describe it as left-associative?
There was a problem hiding this comment.
Oh, it's not actually recursive... Clearly I didn't actually test this properly 😄
I can change the docstring for this method to indicate that it's left-associate instead; should I also take a stab at making a proper recursive version for this PR (and if so, what should it be named, or should it just be a recursive::Bool kwarg to the regular merge)?
base/namedtuple.jl
Outdated
| (a = 1, b = 3, c = (d = 2,)) | ||
| ``` | ||
| """ | ||
| merge(a::NamedTuple, b::NamedTuple...) = merge(merge(a, b[1]), b[2:end]...) |
There was a problem hiding this comment.
This would be a bit more elegant:
merge(a::NamedTuple, b::NamedTuple, cs::NamedTuple...) = merge(merge(a, b), cs...)
There was a problem hiding this comment.
Agreed, and now changed
…make definition more elegant
base/namedtuple.jl
Outdated
| """ | ||
| merge(a::NamedTuple, b::NamedTuple, cs::NamedTuple...) | ||
|
|
||
| Perform a left-associative merge of three or more named tuples. |
There was a problem hiding this comment.
Because regular merge(a::NamedTuple, b::NamedTuple) already handles the two-argument case? I wrote the docstring for just this single method, which accepts only three or mpre arguments. Should I have done it differently?
There was a problem hiding this comment.
Maybe we can combine the two docstrings then?
There was a problem hiding this comment.
What's the best way to merge the docstrings, just copy one of them into the other after 2 newlines and leave this new merge definition without its own docstring? If so, is it ok if I replace merge(a::NamedTuple, b::NamedTuple) definition in the docstring with merge(a::NamedTuple, bs::NamedTuple...), even though none of the individual methods have that exact signature?
|
Do we also want a 1-argument fallback like @peterahrens had in #29362 ? I think this would be useful when splatting into |
|
Yes that would be fine. |
(merge(::NamedTuple...) with more than 2 arguments).
(merge(::NamedTuple...) with more than 2 arguments).
(merge(::NamedTuple...) with more than 2 arguments).
(merge(::NamedTuple...) with more than 2 arguments).
(merge(::NamedTuple...) with more than 2 arguments).
(merge(::NamedTuple...) with more than 2 arguments).
changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Addition of NEWS and compat admonitions for important changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
I only added a single test because I'm highly uncreative; please let me know if there are any more I should add.
P.S. This is my first attempt at contributing to Julia proper, so please let me know if I screwed anything up 😄