Ellen Spertus
05/16/2022, 8:01 PMreturn binding.myField.getWidth() != 0 ? binding.myField.getWidth() : binding.otherField.getWidth()
2️⃣
return binding.myField.getWidth().let {
if (it != 0) it else binding.otherField.getWidth()
}
3️⃣ by @Luke
return if (binding.myField.getWidth() != 0) binding.myField.getWidth() else binding.otherField.getWidth()
Luke
05/16/2022, 8:34 PMreturn if (binding.myField.getWidth() != 0) binding.myField.getWidth() else binding.otherField.getWidth()
Ellen Spertus
05/16/2022, 8:35 PMLuke
05/16/2022, 8:36 PMreturn binding.myField.getWidth().takeUnless { it == 0 } ?: binding.otherField.getWidth()
Luke
05/16/2022, 8:36 PMif
is the most readable optionLuke
05/16/2022, 8:41 PMbinding.myField.getWidth() == 0
vs binding.myField.getWidth() != 0
Ellen Spertus
05/17/2022, 1:47 AMKlitos Kyriacou
05/17/2022, 9:07 AMmyField
width between checking for 0 and returning it. This means it can return 0, something that this if
statement is trying to prevent.