Right way to transform keyword arguments

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

Not sure if this is useful but I think you can also splat the NamedTuple as keyword arguments:

julia> f(; a=1, b=2) = a-b
f (generic function with 1 method)

julia> f(; (b=10, a=20)...)
10

Is of.data is the recommended way to convert the iterator to NamedTuple? Maybe there should be some exported accessor function.

How would it be with

function f(xf...; of...)
    xg = map(transform,xf)
    og = (transform(o) for in pairs(o))
    g(xg...; og...)
end

Here (transform(o) for in pairs(o)) is a chain of two iterators which then gets splatted again, so this should theoretically be not bad.

values(of) appears to give the underlying named tuple (like of.data), so you could use that to make it portable.

function f(xf...; of...)
    xg = map(transform,xf)
    og = pairs(map(transform,values(of)))
    g(xg...; og...)
end

In terms of efficiency, I tried with generator expressions but your map version was better by a long way.

(For reference -

function f2(xf...; of...)
    xg = map(transform,xf)
    og = (key => transform(value) for (key, value) in of)
    g(xg...; og...)
end

it wasn’t very efficient.)

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)