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?
I suspect it's just an oversight; @JeffBezanson?
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.
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.
Named tuples are ordered though, so returning a new named tuple with the first element dropped seems to make sense.
Most helpful comment
Named tuples are ordered though, so returning a new named tuple with the first element dropped seems to make sense.