Suggestion: optional arg names in function literals


#1

If we pass functions that have one parameter, we can use implicit it variable.

for example
_________________________________

fun test(f:(x:String)->Unit){
  f(“invoked here”)
}


test{print(it)};//using implicit it variable
__________________________________

but if we have two or more params in the passing function - we have to define them explicitly:
__________________________________

fun processImage(f : (r : Int, g : Int, b : Int)->Unit) {
  f(1, 2, 3);
}


processImage{r, g, b -> print(“rgb value is: {a} {b} ${c}”) };   
           ________/
           ^
this is a boilerplate code
__________________________________

So my suggestion is the ability to call it without explicitly defining arg names, that are already defined in signature f:(r:Int,g:Int,b:Int)->Unit:
processImage{print(“rgb value is: {r} {g} ${b}”)};

It’s a good syntactic sugar for DSLs

Is it possible to implement?
I know - there is a way to make a tuple with named fields #(r,g,b) and to use it as it.r , it.g, it.b, but it’s not so handy.


#2

Thanks for your suggestion. We'll need to think about it.