Skip to content
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 Base.tail(::NamedTuple). #29595

Merged
merged 2 commits into from
Oct 26, 2018
Merged

Conversation

tpapp
Copy link
Contributor

@tpapp tpapp commented Oct 11, 2018

Fixes #29572.

@@ -273,6 +273,7 @@ values(nt::NamedTuple) = Tuple(nt)
haskey(nt::NamedTuple, key::Union{Integer, Symbol}) = isdefined(nt, key)
get(nt::NamedTuple, key::Union{Integer, Symbol}, default) = haskey(nt, key) ? getfield(nt, key) : default
get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) ? getfield(nt, key) : f()
tail(t::NamedTuple{names}) where names = NamedTuple{tail(names)}(tail(values(t)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think NamedTuple{tail(names)}(t) will work, and is a bit better since it will preserve field types.

@kshyatt
Copy link
Contributor

kshyatt commented Oct 23, 2018

Is this mergeable?

@tpapp
Copy link
Contributor Author

tpapp commented Oct 26, 2018

Friendly ping: if there are changes to be made, please let me know, otherwise if there are no issues it would be nice to have this.

@KristofferC KristofferC merged commit 010495f into JuliaLang:master Oct 26, 2018
@KristofferC KristofferC added the needs news A NEWS entry is required for this change label Oct 26, 2018
@JeffBezanson JeffBezanson removed the needs news A NEWS entry is required for this change label Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants