I define the type
@kwdef mutable struct Tablet{T}
id = nothing
a::T
# ...
end
My program mostly operates on Vectors of these. One thing I need to do is jusxtopose such vectors to make longer vectors. I overload Base.+
for that:
function (Base.:+)(a::Tablet{Any}, b::Tablet{Any})::Vector{Tablet{Any}}
[a, b]
end
function (Base.:+)(a::Tablet{Any}, v::Vector{Tablet{Any}})::Vector{Tablet{Any}}
[a, v...]
end
function (Base.:+)(v::Vector{Tablet{Any}}, b::Tablet{Any})::Vector{Tablet{Any}}
[v..., b]
end
function (Base.:+)(v1::Vector{Tablet{Any}},
v2::Vector{Tablet{Any}})::Vector{Tablet{Any}}
[v1..., v2...]
end
I also overload Base,:*
to repeat individual Tablet
s and Vectors
of Tablet
s:
function (Base.:*)(repeat::Int, t::Tablet{Any})::Vector{Tablet{Any}}
result = Vector{Tablet{Any}}()
for i in 1:repeat
push!(result, copy(t))
end
result
end
function (Base.:*)(repeat::Int, v::Vector{Tablet{Any}})::Vector{Tablet{Any}}
result = Vector{Tablet{Any}}()
for i in 1:repeat
append!(result, copy.(v))
end
result
end
When I try to combine tablets though, I get errors:
let
border_color =RGB(0.5, 0.5, 0.5)
border1 = Tablet(
a=border_color,
b=border_color,
c=border_color,
d=border_color,
threading=BackToFront())
border1 + border1
end
MethodError: no method matching +(::Main.var"workspace#3".Tablet{ColorTypes.RGB{Float64}}, ::Main.var"workspace#3".Tablet{ColorTypes.RGB{Float64}})
Closest candidates are:
+(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:591
top-level scope@Local: 9[inlined]
Why are my methods on Tablet
not candidates?
Thanks.