Constructor with Varargs

Lincoln_Hannah
Thu, 21 Jul 2022 01:56:26 +0000
General Usage

This works

using Pipe, Parameters

@with_kw struct X
    A
    B
end

x = (A=1, B=2 )
X( x... )

but this fails

x = (A=1, B=2, C=3 )
X( x... )

unless you manually filter x to only contain the fields of X.
or manually create a varargs constructor X(; A, B, varargs... ) = X( A, B)

Is there a way around this ?
Can the X struct automatically create a constructor with Varargs… functionality.
So that unused variables are dropped without causing an error

3 posts - 2 participants