Is it possible to create a struct instance without an explicit constructor?

I have this problem where I’m given a DataType for a mutable struct and I have a lot of values corresponding to all the fields for this struct. Trouble is that these values might be out of order so I have no way of loading them into the default constructor foo(“a”, “b”, … “z”)

It would be great if I could create a struct instance with dummy values and then update everything one by one without going off and defining a foo() for each of my structs. Is there a way to do this? Probably I’m just lazy and need better style -.-

If you use the Base.@kwdef you can use keywords to intialize the values. That in combination with keys(), values(), fieldnames(), can give you the tools to build complicated constructors.

(If your structure is mutable maybe just using @kwdef solves all your problems)

2 Likes