A potential reason is the lack of dispatch by keyword arguments. Dispatch can be used with destructuring in a kinda-convenient way:
julia> g((;a,b,c)::NamedTuple{(:a,:b,:c)}) = "abc"
g (generic function with 1 method)
julia> g((;a,b)::NamedTuple{(:a,:b)}) = "ab"
g (generic function with 2 methods)
What if args also contains an element that isn’t a function variable?
Can it still be used without causing an error?
I have a function that takes a 10 inputs and returns 5 outputs.
I want to run it on each row of a CSV which has 30 columns. The necessary field names match with the keyword arguments so I’d like to just send each row to the function without having to filter it down.
As shown below this gives an error.
function f(; a=0, b=0 )
x = a + b
y = a - b
(; x, y)
end
D1 = DataFrame( a=1:5 )
D2 = DataFrame( a=1:5, C = 1:5 )
@pipe eachrow(D1) .|> f(;_...) |> DataFrame #works
@pipe eachrow(D2) .|> f(;_...) |> DataFrame #Error - no C element in function parameters
Another option
transform with ByRow is a fantastic function.
but you need to map both the inputs and outputs
If the field names match the function inputs / outputs it would be great you could just tell it to map each row.
transform(D2, :a => ByRow( a-> f(a=a)) => [:x,:y] ) #works
transform(D2, ALL_COLUMNS => f => COLUMN_NAMES_FROM_OUTPUT ) #Nice to have