Here is a sketch of some code I’m currently working on that uses destructuring for its convenience:
...
lens = (; f1, α, β, γ, y3, sinθ, ϵᵣ)
opts = (;
ap_split = 2,
ap_point = 0.0,
ap_compensate = false,
bp_split = 2,
bp_point = 0.0,
bp_compensate = true,
ap_apex = 0.046,
bp_apex = 0.046,
ap_length=0.423,
bp_length=0.423,
λ)
lens = RotmanLens.rl_solve(lens)
lens = RotmanLens.port_apertures(lens, opts)
lens = RotmanLens.rl_excite(lens, opts)
...
The functions are set up like this:
function rl_solve(lens::NamedTuple)
(; f1, α, β, γ, y3, sinθ, ϵᵣ) = lens # Deconstruct fields
xya = similar(y3, SV2)
xyb = similar(sinθ, SV2)
w = similar(y3)
... # Compute entries of xya, xyb, w
return merge(lens, (; xya, xyb, w))
end
Each function destructures whatever fields are needed from lens::NamedTuple
and merges in the part that is computed locally. It is much more convenient than tracking many inputs and outputs.