Broadcasted assignment of custom types

Btw, another way of creating a with identical objects is:

julia> struct Foo x::Vector{Int} end

julia> a = fill(Foo([2]), 2)
2-element Array{Foo,1}:
 Foo([2])
 Foo([2])

(There’s also fill!.) In case you want unique objects, you can do:

julia> a = 1:2 .|>_-> Foo([2])
2-element Array{Foo,1}:
 Foo([2])
 Foo([2])

julia> push!(a[1].x, 3);

julia> a
2-element Array{Foo,1}:
 Foo([2, 3])
 Foo([2])
3 Likes