In Kotlin, you have standard extension functions like
Each of these do a very comparable job - inlining some code, such that you don’t have to declare a variable or use a variable. The difference is that 2 of these have a function with a receiver, instead of a parameter, and 2 of these return the result of the function, as opposed to the parameter input (so the function returns Unit), such that there’s one for each combination of these.
I’ve always found it difficult to memorize which of these does exactly what. It’s too late to change now, but I think it would be possible to make it much more intuitive by allowing the caller to decide whether the first parameter is a receiver. Obviously, this idea carries over to all lambda functions. That way, you only need 2 of these. It doesn’t functionally change anything, other than that no 2 separate functions are required to do the exact same thing - with a slightly different syntax.
That could reduce it to
T.apply(...) for example.
As for how this would look syntactically, the simplest way would be to explicitly declare the parameter name “this”.
It’s a little long this way though, looking for better options.