Travis Griggs
01/09/2024, 7:15 PMVampire
01/09/2024, 7:26 PMJeff Lockhart
01/09/2024, 7:27 PMthing?.run {
foo()
}
or passing the variable as a parameter to other functions, e.g.:
thing?.let {
foo(it)
}Travis Griggs
01/09/2024, 7:38 PMJeff Lockhart
01/09/2024, 7:59 PMlet at times when I'm using functions and properties with it as a receiver, but need to disambiguate those calls from the parent this scope. It really just comes down to which best fits the particular code in each scenario. There's not always a right or wrong answer.CLOVIS
01/09/2024, 10:37 PMrun overload with a receiver. I use let for transformations, and the receiver-less run for semantic scoping:
val foo = bar ?: run {
log.info("something")
return
}ephemient
01/10/2024, 1:01 AMwith(foo) { ... } than foo.run { ... }, but will use ?.run { ... } sometimes if that's what's works betterKlitos Kyriacou
01/10/2024, 10:01 AMlet and run to disambiguate between two different things without having to use specific names instead of `it`:
foo().let {
bar().run {
// Here, you can refer to foo()'s returned value as "it" and bar()'s as "this"
}
}
Having said that, I've never actually done this in real code.