Unpack an object by fieldnames into local scope?

Is there a macro or syntax that will unpack an object (such as a struct or a LabelledArray) into local variables by it’s field names?

So given

struct MyObj
    a::Int
    b::Int
end

m1 = MyObj(3,4)

@splatbyfnames m1 would be equivalent to a,b = m1.

Thanks!

Have a look at UnPack.jl and Parameters.jl.

1 Like

Thank you. I think the (somewhat dangerous) @unpack_... macros in Parameters.jl are what I’m looking for.

Another option is StaticModules.jl, which provides a @with macro.

1 Like