Has there been any addition in Julia 1.4/1.5 of function return inference, given arg types? As of Julia 1.3, I was using
_detect_type(fn, itr) = eltype(map(fn, empty(itr)))
function myfunc(fn, itr)
result = Vector{_detect_type(fn, itr)}(undef, N)
...
end
to pre-allocate memory in such a way that the inference engine would keep myfunc
type-stable. But this method breaks down on anything without an empty
function (eg a Generator of an arbitrary struct).
That _detect_type
was always a hack. Has a method to infer function return types at compile time been added recently, by any chance? Just hoping…
(PS. I wonder if I am doing something in a non-Julian fashion that this concept does not seem to have been a priority.)