Skip to content

Commit 5bf40b3

Browse files
committed
Add Base.tail(::NamedTuple).
Fixes JuliaLang#29572.
1 parent e20d1ee commit 5bf40b3

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/namedtuple.jl

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ values(nt::NamedTuple) = Tuple(nt)
273273
haskey(nt::NamedTuple, key::Union{Integer, Symbol}) = isdefined(nt, key)
274274
get(nt::NamedTuple, key::Union{Integer, Symbol}, default) = haskey(nt, key) ? getfield(nt, key) : default
275275
get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) ? getfield(nt, key) : f()
276+
tail(t::NamedTuple{names}) where names = NamedTuple{tail(names)}(tail(values(t)))
276277

277278
@pure function diff_names(an::Tuple{Vararg{Symbol}}, bn::Tuple{Vararg{Symbol}})
278279
names = Symbol[]

test/namedtuple.jl

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ end
105105
@test get(()->0, (a=1, b=2, c=3), :a) == 1
106106
@test get(()->0, NamedTuple(), :a) == 0
107107
@test get(()->0, (a=1,), :b) == 0
108+
@test Base.tail((a = 1, b = 2.0, c = 'x')) (b = 2.0, c = 'x')
109+
@test Base.tail((a = 1, )) NamedTuple()
110+
@test_throws MethodError Base.tail(NamedTuple())
108111

109112
# syntax errors
110113

0 commit comments

Comments
 (0)