I've just come across this control structure: ```(...
# intellij
k
I've just come across this control structure:
Copy code
(some+complicated+expression).let { value ->
    when (value) {
        ...
    }
}
Is there any automated refactoring available to simplify it to this?
Copy code
when (val value = some+complicated+expression) {
    ...
}
a
There is an inspection
Kotlin | Redundant constructs | Redundant receiver-based 'let' call
which provides a fix to remove redundant
let
, though it seems, it doesn't work in all cases. Could you please provide the full code snippet to check? Thanks
k
Hi Anna, thanks for your reply. Here's a contrived minimal example:
Copy code
fun main(args: Array<String>) {
    (args.size * 100 + 10).let { println(it) } // "Redundant 'let' call could be removed"
    (args.size * 100 + 10).let { // No inspection offered
        when (it) {
            10 -> println("a")
            110 -> println("b")
            else -> println("c")
        }
    }
}