# Error broadcasting a function for a custom type

**URL:** <https://discourse.julialang.org/t/error-broadcasting-a-function-for-a-custom-type/54488>\
**Category:** New to Julia\
**Created:** [February 2, 2021, 8:31pm UTC](https://discourse.julialang.org/t/error-broadcasting-a-function-for-a-custom-type/54488 "2021-02-02T20:31:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 2, 2021, 8:31pm UTC](https://discourse.julialang.org/t/error-broadcasting-a-function-for-a-custom-type/54488/1 "2021-02-02T20:31:00Z")

</div>

In the DaysCount package there is the following function:

```julia
abstract type DayCount end
struct Actual365Fixed <: DayCount end
    
function yearfrac(startdate, enddate, ::Actual365Fixed)
    return Dates.value(enddate - startdate) /365
end

```

When trying to broadcast the above function with:

```julia
using Dates
startdate = Date(2020,11,3)
enddate = [Date(2021,1,1),Date(2021,2,2)]
yearfrac.(startdate, enddate, Actual365Fixed())

```

one gets the following error:

```julia
ERROR: LoadError: MethodError: no method matching length(::Actual365Fixed)

```

What am I doing wrong? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [February 2, 2021, 8:43pm UTC](https://discourse.julialang.org/t/error-broadcasting-a-function-for-a-custom-type/54488/2 "2021-02-02T20:43:27Z")

</div>

You just need to tell the broadcast call to treat your `Actual365Fixed` as a scalar, rather than a collection, by wrapping it in a `Ref()`. See [Is there a reason a `MersenneTwister` value is not broadcastable? - #13 by stevengj](https://discourse.julialang.org/t/is-there-a-reason-a-mersennetwister-value-is-not-broadcastable/20774/13) for more info.

---

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 2, 2021, 9:14pm UTC](https://discourse.julialang.org/t/error-broadcasting-a-function-for-a-custom-type/54488/3 "2021-02-02T21:14:37Z")

</div>

> You just need to tell the broadcast call to treat your `Actual365Fixed` as a scalar, rather than a collection, by wrapping it in a `Ref()`

It works perfectly. Thank you very much!
