You mix the designation of the Java lambda with the Kotlin musical notation, creating a lambda that returns in this case another nested lambda. The correct and idiomatic syntax would look like this:
switchAction.setOnCheckedChangeListener { _, isChecked -> preferences.userStatus = isChecked switchToggleVisibility(isChecked) if (isChecked) { fetchStats() getOrders() } else { releaseOrder() } }
Taking in all the noise, a normal lambda looks like this:
{ arg1, arg2 -> returnValue }
You did it:
{ arg1, arg2 -> { returnValue } }
What can also be written like this:
{ arg1, arg2 -> { -> returnValue } }
This notation makes it a little clearer that a lambda does not return a return value, but returns another lambda without parameters returning a return value.
Usually this will depend on the compiler as the wrong return type, but in your case, the return value of the lambda is not used. So, you just create an inner lambda without returning or starting it, so you get a warning.
source share