-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
delete for NamedTuples #27725
delete for NamedTuples #27725
Changes from 5 commits
e747501
fdd3a98
a239411
36af455
e33cea2
fc46f7a
0338959
0bc6e80
354d543
cf160bb
ec186c5
524bc8b
65aac32
db79715
14dbfd2
292d88e
619fe4c
3606bec
d43cf81
99a3d20
be15cc1
a4abb90
2f37e71
308deb6
e1ae2de
86a4b12
5226c03
ea3aeae
4704588
2202264
b10fced
6f6f25b
993cc2b
54198b3
14d0b46
5559d8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,6 +482,7 @@ export | |
firstindex, | ||
collect, | ||
count, | ||
delete, | ||
delete!, | ||
deleteat!, | ||
eltype, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,16 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) | |
(names...,) | ||
end | ||
|
||
""" | ||
delete(nt::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} | ||
|
||
Construct a copy of a named tuple `nt`, omitting the fields named in `omitnames`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps |
||
""" | ||
function delete(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} | ||
names = diff_names(an, omitnames) | ||
NamedTuple{names}(a) | ||
end | ||
|
||
""" | ||
structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn},Type{NamedTuple{bn}}}) where {an,bn} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,12 @@ end | |
abstr_nt_22194_3() | ||
@test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] | ||
|
||
@test Base.delete((a=1, b=2), (:b,)) == (a=1,) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I read that the result here should be inferrable? If so, should these test also check that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I test that? Guessed this for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
@test Base.delete((a=1, b=2), (:a,)) == (b=2,) | ||
@test Base.delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) | ||
@test Base.delete((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) | ||
@test Base.delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() | ||
|
||
@test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) | ||
@test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) | ||
@test Base.structdiff((a=1, b=2, z=20), (b=3, q=20, z=1)) == (a=1,) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeffreySarnoff do you think it is really necessary to give the parametric type in the named tuple? I don't think the
{an} where {an}
adds something and makes the docstring longer and less readable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the form used in another NamedTuple function. The
an
captures the names directly, rather than requiring a separate function call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to the documentation string. Should the user care about this implementation detail? Isn't it anyway clear that a named tuple is parametricaly defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really, though for the docstring could be given without that and still be valid -- just not matching
I have no idea if that is frowned upon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will shorten the doc string -- and if there are voices to put it back -- I will do that.