Consider an existing function in Base, which takes in a variable number of arguments of some abstract type T
. I have defined a subtype S<:T
and would like to write a method which dispatches if any of the arguments is my subtype S
.
As an example, consider function Base.cat
, with T
being an AbstractArray
and S
being some MyCustomArray <: AbstractArray
.
Desired behaviour:
julia> v = [1, 2, 3];
julia> cat(v, v, v, dims=2)
3×3 Array{Int64,2}:
1 1 1
2 2 2
3 3 3
julia> w = MyCustomArray([1,2,3])
julia> cat(v, v, w, dims=2)
"do something fancy"
Attempt:
function Base.cat(w::MyCustomArray, a::AbstractArray...; dims)
pritnln("do something fancy")
end
But this only works if the first argument is MyCustomArray
.
What is an elegant way of achieving this?