# NestedStructInitialiser.jl

**URL:** <https://discourse.julialang.org/t/nestedstructinitialiser-jl/52159>\
**Category:** Package Announcements\
**Created:** [December 21, 2020, 8:43am UTC](https://discourse.julialang.org/t/nestedstructinitialiser-jl/52159 "2020-12-21T08:43:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [December 21, 2020, 8:43am UTC](https://discourse.julialang.org/t/nestedstructinitialiser-jl/52159/1 "2020-12-21T08:43:18Z")

</div>

> **[GitHub - jbrea/NestedStructInitialiser.jl](https://github.com/jbrea/NestedStructInitialiser.jl)**
>
> Contribute to jbrea/NestedStructInitialiser.jl development by creating an account on GitHub.

If this is useful for somebody else, I’ll register it.

From the README:

`NestedStructInitialiser` exports two functions: `parameters` helps to explore  
nested structures and `initialiser` creates efficient constructors for nested  
structures.

```julia
julia> using NestedStructInitialiser, StaticArrays, Unitful
julia> struct A{N}
        b
        c
        t::NTuple{N, Float64}
    end
julia> struct B{T}
        m::T
        n::Float64
        o::Int
    end
julia> struct C{N}
        x::SVector{N, Float64}
    end

julia> p = parameters(A)
A Parameters
Fixed
 none
Free
 b: Any (indeterminable dimensionality)
 c: Any (indeterminable dimensionality)
 t: Tuple{Vararg{Float64,N}} where N (indeterminable dimensionality)

julia> p = parameters(A{2}, b = B{typeof(1.0u"s")}, c = C{2}, o = 42, n = () -> rand())
A{2} Parameters
Fixed
 b = B{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}}
 n = #9
 o = 42
 c = C{2}
Free
 m: Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}
 x: SArray{Tuple{2},Float64,1,2}
 t: Tuple{Float64,Float64}

julia> constructor = initialiser(p)

julia> constructor([1, 2, 3, 4, 5])
A{2}(B{Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}}(1.0 s, 0.5556739449879704, 42), C{2}([2.0, 3.0]), (4.0, 5.0))

```
