Re:Namedtuple in a Post-Dataclasses World
by bobbylarrybobby on Wednesday July 21, 2021 @12:16PM
(#27908221)
And to create one as an anonymous type, you can use the `@NamedTuple` macro:
julia> @NamedTuple{x::Int, y::String}
NamedTuple{(:x, :y), Tuple{Int64, String}}I guess one difference is that when you inspect it, it doesn't indicate that it is a `point`, just that it's named tuple of two variables, so it's not exactly equivalent.
Re:Namedtuple in a Post-Dataclasses World
by mdcfrancis on Wednesday July 21, 2021 @03:21PM
(#27910825)
they are also, type stable, strongly typed and have the same overhead as a struct. So an array of NamedTuples takes the minimal space and allocation.
julia> point = (x=1, y=2)
(x = 1, y = 2)
julia> point.x
1
julia> point.y
2
julia> dump(point)
NamedTuple{(:x, :y), Tuple{Int64, Int64}}