advertise ccolor
in writing generic code
#151
Labels
best practice
workflows and best practice that are useful in JuliaImages and/or Julia
Functions in JuliaImages should accept both numerical array
AbstractArray{<:Number}
and colorant arrayAbstract{<:Colorant}
if possible.It is not uncommon to infer the return eltype in the beginning of the algorithm so as to pre-allocate array. I previously have two versions of codes to achieve this. The first version is:
Then one day I found out that
eltype(Float32) == Float32
, which make it possible to merge it into one method:As @kimikage pointed it out in JuliaGraphics/ColorTypes.jl#201,
ccolor
does a similar thing more reliably (I assume so?):I feel this worth documenting somewhere in the tutorials; otherwise, it's like a missing spell and people repeatedly reinvent it.
The text was updated successfully, but these errors were encountered: