-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add setindex for named tuples #33468
Conversation
One possible improvement is to re-use the code from function merge(a::NamedTuple{an}, b::NamedTuple{bn}) where {an, bn}
if @generated
names = merge_names(an, bn)
types = merge_types(names, a, b)
vals = Any[ :(getfield($(sym_in(n, bn) ? :b : :a), $(QuoteNode(n)))) for n in names ]
:( NamedTuple{$names,$types}(($(vals...),)) ) |
cc @mbauman |
I don't see how this creates a "test ambiguous" :/ |
Co-Authored-By: Matt Bauman <[email protected]>
re-opening for some failing checks |
I added a bunch of tests in addition to the docstring |
@mbauman I believe this is getting good. The failure is a connection problem |
I have two questions:
|
In the case of
Is the syntax named_tuple[::Integer] really used much? It is not in the docstring of |
I think this should support integer indices, but it has to be a separate method since it can't use |
Co-Authored-By: Jeff Bezanson <[email protected]>
Co-Authored-By: Jeff Bezanson <[email protected]>
I have an RFC on generic |
Given that
Base.setindex
is now documented, I think it makes some sense to have it defined forNamedTuple
s as well.The implementation may be naive here and uses
merge(::NamedTuple, itr)
, given that the left argument re-writes member already present in the first argument