If f(xf...;of...) is going to call g(xg...; og...) after applying some transformations xf->xg and of->og, what is the most efficient way to do this? of happens to be a pairs iterator of NamedTuples, so direct map on it doesn’t work. Here is what I managed but I don’t think it is portable:
function f(xf...; of...)
xg = map(transform,xf)
og = pairs(map(transform,of.data))
g(xg...; og...)
end
Thanks for all the responses. Here is a benchmark comparing different suggestions:
julia> @benchmark og = (x[1]=>sum(x[2]) for x in of)
minimum time: 71.074 ns (0.00% GC)
julia> @benchmark collect(x[1]=>sum(x[2]) for x in of) # note that this gives an array
minimum time: 260.378 ns (0.00% GC)
julia> @benchmark og = pairs(map(sum, values(of)))
minimum time: 118.039 ns (0.00% GC)
julia> @benchmark og = collect(map(sum, values(of)))
minimum time: 130.588 ns (0.00% GC)