Does anyone else find trailing lambdas confusing? Especially when learning, I wish I could tell Inte...
v
Does anyone else find trailing lambdas confusing? Especially when learning, I wish I could tell IntelliJ to reformat all code to be explicit about trailing lambdas - it would really help me to understand what is actually going on. Or perhaps a different block delimitator could have been chosen, besides { }, to make it clearer. Or maybe it's just me!
🚫 2
b
You can always use named arguments if you want.
Copy code
fun target(lambda: () -> Unit)

//Use it with trail
fun test() = target { println("trailing") }

//Or without it
fun test1() = target(lambda = { println("no trail") })
I personally love trailing lambdas
âž• 7
v
Once you are familiar with them, they are useful. But when learning a new framework or tool, I'd find it really helpful if IntelliJ could just be a bit more explicit on my behalf. Because otherwise I'm having to guess what the trailing lambda part actually is.
b
I find rainbow brackets intellij plugin helpful in this regard
Makes it quite visual and easy to spot each lambda scope
v
Thanks, I'll try it out!
m
you can use Intellij’s intentions to convert it to an ordinary argument: alt+enter on your trailing lambda
Schermata 2021-04-09 alle 17.04.10.png