A (un)splat operator for named arguments
Opened this issue · 12 comments
What I'd like is for it to behave just like a regular function application, so:
local foo(x, y=100, z) = { x: x, y: y, z: z }
local bar = {
x: 1,
y: 2
}
foo(**bar) # Should return { x: 1, y: 100, z: 2 }
Going the other way would also be nice:
local foo(**kwargs) = kwargs
foo(x=6, y=1) # Should return { x: 6, y: 1 }
I've been wondering whether to just do Python semantics *args
**kwargs
or to instead have a ...
keyword that encompasses both and is a bit cleaner.
My general preference is for cleanliness over similarity to python, but others might feel differently 😄
The ...
syntax will only cover declaring various forms of varargs, while (as I understood it) this FR was primarily about invoking a function with a programmatically constructed list of (possibly keyword) arguments.
@igorpeshansky it's both, but yes, I certainly care about invoking more (since that's the one that's harder right now)
I may be missing something, but how would the ...
keyword be used to invoke a function?
I don't understand your examples at all, what programming language are they even in and why should z be 2?
arg sorry, I somehow got linked here from nix and thought I'm still in the nix thread...
no worries :)
This would be killer for templating out config files....
Same here, splat operators would be very useful.
Do you know of any workaround to call a function dynamically using arguments that are currently available as object fields?
This would be quite useful. At the minimum, it would save me from having to wrap the variadic args in []
.