I’m trying to splice!
a custom structure into an array containing my custom structures, something like:
mutable struct MyType
a::Int64
b::Float64
c::Bool
end
MyType() = MyType(0, 0.0, false)
myvec = [MyType() for i in 1:10]
splice!(myvec, 3:2, MyType(1, 1.0, true))
What Base
functions do I have to define in order to do this? When I call , I get an error telling me
ERROR: MethodError: no method matching length(::MyType)
I define Base.length(x::MyType) = 1
but then need to define Base.iterate(::MyType)
. I’m guessing that my length
extension should be something like Base.length(v::Vector{MyType})
instead (and similarly for iterate
, but I’m not sure. Any help would be appreciated, thanks!