Unitful and generic function types

It’s a little weird to me that ustrip doesn’t take the Quantity type as an input like unit can, so this would be what that would look like:

julia> extra_ustrip(::Type{Q}) where {T, Q<:Quantity{T}} = T
extra_ustrip (generic function with 1 method)

julia> extra_ustrip(typeof(1*u"s")) # replace input with `T` in your code
Int64

julia> extra_ustrip(typeof(1im*u"s"))
Complex{Int64}

But I don’t know how that would be multiplied with u"s".

You don’t provide much detail, so let’s say we write the results of bar(x, y) to my_array. For that to work, we need eltype(my_array) == eltype(bar(x,y)). This isn’t easy to deal with automatically; the output type of the first elementwise operation is not necessarily the same as the following ones, which is why the output type mechanisms for broadcasting are complex and stayed internal. The common practice is to pass the output eltype or the preallocated output array itself to foo, leaving another function to figure out the automatic output type mechanism for your own context or allowing you to manually provide the expected output type for x and y.