Instantiate concrete type programmaticaly

I want to instantiate a the following concrete type,

Base.@kwdef struct A
    x::Int
    y::Int = 123
end

but I’m having problems when all fields are not given.
While this works:

julia> a = A([1, 2]...)
A(1, 2)

julia> A(x=1)
A(1, 123)

But the following does not work:

julia>  A([1]...)
ERROR: MethodError: no method matching A(::Int64)

Note that I want to instantiate a composite type where the values for all (or the required) fields are given in a vector. How can I achieve this?

Does this work for you?

julia> A(; (x=1,)...)
A(1, 123)

julia> A(; NamedTuple{(:x,)}([1]...)...)
A(1, 123)
1 Like