That should be trivial, but after a few minutes trying, I still can't figure it out:
p = pairs((a=1,b=2))
keys(p) # works
values(p) # fails: returns named tuple
The documentation of Pairs is non-existent in the manual.
One possible solution:
[pi.second for pi in p]
Iterators.map(last, p) will do it
keys and values API is a total mess
I looked at it once and then got really mad and had to stop looking
It is :grapes:
actually this was just about my very first ever submitted GH issue https://github.com/JuliaLang/julia/issues/49932
Why is it returning a NamedTuple a failure?
For better or worse, NamedTuple does act like a value collection, not a key-value collection:
julia> v = values(p)
(a = 1, b = 2)
julia> for x in v
println(x)
end
1
2
I think it comes from the context. I am bumping into this when I am processing kwargs:
f(; kwargs...) = kwargs
Inside the function f I would like to extract the names of the keywords and their values.
So I would expect kwargs to behave like a named tuple.
the NamedTuple is a collection of values though
I know. It is a bit weird though.
Fair enough
Júlio Hoffimann has marked this topic as resolved.
values(values(kwargs)) if you want a Tuple?
Also an option. Thanks.
I wish all these inconsistencies were gone in the future after careful review of iteration on these objects
Last updated: Nov 27 2025 at 04:44 UTC