# \`splice!\` for vector of structs

**URL:** <https://discourse.julialang.org/t/splice-for-vector-of-structs/25898>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 1, 2019, 5:04pm UTC](https://discourse.julialang.org/t/splice-for-vector-of-structs/25898 "2019-07-01T17:04:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [July 1, 2019, 5:04pm UTC](https://discourse.julialang.org/t/splice-for-vector-of-structs/25898/1 "2019-07-01T17:04:00Z")

</div>

I’m trying to `splice!` a custom structure into an array containing my custom structures, something like:

```julia
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

```julia
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!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [July 1, 2019, 5:13pm UTC](https://discourse.julialang.org/t/splice-for-vector-of-structs/25898/2 "2019-07-01T17:13:08Z")

</div>

Try `splice!(myvec, 3:2, [MyType(1, 1.0, true)])` (i.e., wrap the third argument in a vector). I think the problem is not that you need to define `length` and `iterate` for your object, but that the `splice!` method takes a collection of objects in the third argument to use as replacement, not just one replacement object.
