I often try to write mutating functions to avoid unnecessary allocation. But sometimes I have to use the same function and allocate a new array. This usually means that I have to create a new function with almost the same content.
A = randn(3) function foo!(A) A .= A ./ 2 return nothing end function foo() A = randn(3) A .= A ./ 2 return A end
Is there a good practise to avoid copy/paste of mutating functions into normal functions? Would this example is considered a right approach?
function foo2() A = randn(3) foo!(A) return A end