Skip to content

Commit 458b449

Browse files
KristofferCStefanKarpinski
authored andcommitted
add an example of programatically creating a named tuple (#32330)
1 parent b8148ec commit 458b449

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

base/namedtuple.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ julia> collect(pairs(x))
4444
:a => 1
4545
:b => 2
4646
```
47+
48+
In a similar fashion as to how one can define keyword arguments programmatically,
49+
a named tuple can be created by giving a pair `name::Symbol => value` or splatting
50+
an iterator yielding such pairs after a semicolon inside a tuple literal:
51+
52+
```jldoctest
53+
julia> (; :a => 1)
54+
(a = 1,)
55+
56+
julia> keys = (:a, :b, :c); values = (1, 2, 3);
57+
58+
julia> (; zip(keys, values)...)
59+
(a = 1, b = 2, c = 3)
60+
```
4761
"""
4862
Core.NamedTuple
4963

0 commit comments

Comments
 (0)