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

no Base.tail for NamedTuple #29572

Closed
tpapp opened this issue Oct 9, 2018 · 4 comments
Closed

no Base.tail for NamedTuple #29572

tpapp opened this issue Oct 9, 2018 · 4 comments

Comments

@tpapp
Copy link
Contributor

tpapp commented Oct 9, 2018

julia> Base.tail((a = 1, b = 2))
ERROR: MethodError: no method matching tail(::NamedTuple{(:a, :b),Tuple{Int64,Int64}})
Closest candidates are:
  tail(::Tuple) at essentials.jl:173
Stacktrace:
 [1] top-level scope at none:0

julia> VERSION
v"1.1.0-DEV.431"

Is this intentional, or is it just waiting for me to make a PR?

@StefanKarpinski
Copy link
Member

I suspect it's just an oversight; @JeffBezanson?

@JeffBezanson
Copy link
Member

Yes this can be added. tail is not exported, but also the named tuples API is deliberately minimal since adding new, otherwise undefined methods is non-breaking. That gives us time to decide what should be defined and how it should work.

@tpapp
Copy link
Contributor Author

tpapp commented Oct 10, 2018

Reflecting on this, think I agree with the wait & see approach, since I am not sure what semantics I would find useful. Originally I was expecting

Base.tail((a = 1, b = 2, c = 3)) == (b = 2, c = 3)

but then it turned out I need to work with the values anyway, which is a ::Tuple and I can just use Base.tail. Also, first returns just the first value, so

(first(x), Base.tail(x)...) == x

would not hold either.

The alternative is making

Base.tail(nt::NamedTuple) = Base.tail(values(nt))

which seems kind of contrived too.

@JeffBezanson
Copy link
Member

Named tuples are ordered though, so returning a new named tuple with the first element dropped seems to make sense.

tpapp added a commit to tpapp/julia that referenced this issue Oct 11, 2018
KristofferC pushed a commit that referenced this issue Oct 26, 2018
* Add Base.tail(::NamedTuple).

Fixes #29572.

* Simplify, as suggested by @JeffBezanson.
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

No branches or pull requests

3 participants