For a struct s which has parameters given by parameters, iterates through all non-leaf nodes and collects the marked fields into a flat vector. This is particularly useful for model training or optimization, or use with ForwardDiff. A function which restructures s according to a flat vector is returned as the second argument.

NOTE: The flat vector representation is a Vector{T}. Julia will promote all entries to a common type if possible. This means [1, 2.0] == [1.0, 2.0] and both are Vector{Float64}.

fieldmap(f, x; exlude = isleaf)

Maps the function f over the fields of a FlexibleFunctor (equivalently, the parameter fields of a struct s given by parameters).

restructure(s, xs)

Given a struct s with parameters given by parameters, restructures s according to the vector xs. In particular, s == restructure(s, destructure(s)[1]).