# Which methods must be implemented for a custom type to support broadcasting

**URL:** <https://discourse.julialang.org/t/which-methods-must-be-implemented-for-a-custom-type-to-support-broadcasting/657>\
**Category:** General Usage\
**Tags:** broadcast\
**Created:** [November 30, 2016, 5:54pm UTC](https://discourse.julialang.org/t/which-methods-must-be-implemented-for-a-custom-type-to-support-broadcasting/657 "2016-11-30T17:54:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kkmann/32/1727_2.png) [@kkmann](https://discourse.julialang.org/u/kkmann)\
**Post date:** [November 30, 2016, 5:54pm UTC](https://discourse.julialang.org/t/which-methods-must-be-implemented-for-a-custom-type-to-support-broadcasting/657/1 "2016-11-30T17:54:04Z")

</div>

Hey,

I wanted to leverage the new “.” notation for broadcasting for methods of a custom type, which methods does the type need in order to support automatic broadcasting?

say

```
type A
    val::Float64
end

function f(a::A, x::Float64)::Float64 x end

a = A(1.0)
f.(a, [1.0; 2.0])

```

This initially throws a error about “size” not being implemented and function size(x::A) size(1) end resolves this,  
but the next issue is getindex… Is there like a list of methods I need to get “.” running with methods for “A”?

---

<div class="post-metadata">

**Author:** ![PabloZubieta](https://avatars.discourse-cdn.com/v4/letter/p/ee7513/32.png) [@PabloZubieta](https://discourse.julialang.org/u/PabloZubieta)\
**Post date:** [November 30, 2016, 6:15pm UTC](https://discourse.julialang.org/t/which-methods-must-be-implemented-for-a-custom-type-to-support-broadcasting/657/2 "2016-11-30T18:15:30Z")

</div>

That example should work on the master branch without defining any additional method. On 0.5, for a custom type, you need `size` and `getindex`. For your example above, just define

```
Base.size(::A) = ()
Base.getindex(a::A, i) = a

```

---

<div class="post-metadata">

**Author:** ![kkmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kkmann/32/1727_2.png) [@kkmann](https://discourse.julialang.org/u/kkmann)\
**Post date:** [December 1, 2016, 9:32am UTC](https://discourse.julialang.org/t/which-methods-must-be-implemented-for-a-custom-type-to-support-broadcasting/657/3 "2016-12-01T09:32:17Z")

</div>

Thanks a lot, easier than I feared ;). For all those looking for a quick-and-dirty fix: It also works if you simply call f.([a], [1…0; 2.0]), i.e. by creating an single item array on the fly.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [December 1, 2016, 1:33pm UTC](https://discourse.julialang.org/t/which-methods-must-be-implemented-for-a-custom-type-to-support-broadcasting/657/4 "2016-12-01T13:33:17Z")

</div>

More generally, the methods you need to implement to support a given interface are presented [in the manual](http://docs.julialang.org/en/stable/manual/interfaces/).
