# What properties must a custom type have, to work with the new vectorised syntax?

**URL:** <https://discourse.julialang.org/t/what-properties-must-a-custom-type-have-to-work-with-the-new-vectorised-syntax/2244>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 23, 2017, 1:11am UTC](https://discourse.julialang.org/t/what-properties-must-a-custom-type-have-to-work-with-the-new-vectorised-syntax/2244 "2017-02-23T01:11:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ward9250](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ward9250/32/42768_2.png) [@Ward9250](https://discourse.julialang.org/u/Ward9250)\
**Post date:** [February 23, 2017, 1:11am UTC](https://discourse.julialang.org/t/what-properties-must-a-custom-type-have-to-work-with-the-new-vectorised-syntax/2244/1 "2017-02-23T01:11:11Z")

</div>

I was reading up on the new vectorized function syntax, and I wanted to try it out with BioSequence from the package Bio.jl and a toy example (below). BioSequences behave like a vector/array{1} of various subtypes of Nucleotide, but they are not AbstractArrays or anything like that.

I was wondering if there were a number of methods or characteristics a user defined type must have in order to work with the new vectorised/broadcast function syntax.

```julia
julia> using Bio.Seq

julia> ismismatch(a::Nucleotide, b::Nucleotide) = a != b
ismismatch (generic function with 1 method)

julia> as = dna"AAAAAAAAAA"
10nt DNA Sequence:
AAAAAAAAAA

julia> bs = dna"AAAAAATTTT"
10nt DNA Sequence:
AAAAAATTTT

julia> ismismatch.(as, bs)
ERROR: MethodError: no method matching getindex(::Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}, ::CartesianIndex{1})
 in macro expansion at ./broadcast.jl:127 [inlined]
 in macro expansion at ./simdloop.jl:73 [inlined]
 in macro expansion at ./broadcast.jl:123 [inlined]
 in _broadcast!(::#ismismatch, ::Array{Bool,1}, ::Tuple{Tuple{Bool},Tuple{Bool}}, ::Tuple{Tuple{Int64},Tuple{Int64}}, ::Tuple{Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}},Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}}, ::Type{Val{2}}) at ./broadcast.jl:117
 in broadcast!(::Function, ::Array{Bool,1}, ::Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}, ::Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}) at ./broadcast.jl:172
 in broadcast_t(::Function, ::Type{T}, ::Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}, ::Vararg{Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}},N}) at ./broadcast.jl:228
 in broadcast(::Function, ::Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}, ::Bio.Seq.BioSequence{Bio.Seq.DNAAlphabet{4}}) at ./broadcast.jl:230

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 23, 2017, 2:50am UTC](https://discourse.julialang.org/t/what-properties-must-a-custom-type-have-to-work-with-the-new-vectorised-syntax/2244/2 "2017-02-23T02:50:44Z")

</div>

None on 0.6. Hard/impossible to fix on 0.5.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 23, 2017, 2:53am UTC](https://discourse.julialang.org/t/what-properties-must-a-custom-type-have-to-work-with-the-new-vectorised-syntax/2244/3 "2017-02-23T02:53:41Z")

</div>

Actually I assumed that you want to use them as scalar, which should be the default now on 0.6.

If you want them to behave like arrays, ref [https://github.com/JuliaLang/julia/issues/20740](https://github.com/JuliaLang/julia/issues/20740), though I’ve only seen extending it for `AbstractArray`s.
