arekolek
03/06/2019, 9:25 AMfun foo(bar: List<Int>): Int {
check(bar.isNotEmpty())
return bar.max()!! / 2
}
How would you deal with max
returning a nullable value, other than !!
? Does it bother you?wbertan
03/06/2019, 9:29 AMfoo
is fine to thrown exception (as I suspect based on the check
), you can do something like:
fun foo(bar: List<Int>): Int =
bar
.max()
?.let { it / 2 }
?: throw Exception("foo failed")
Marc Knaup
03/06/2019, 9:50 AMerror("foo failed")
instead of throw Exception
Pavlo Liapota
03/06/2019, 2:03 PM.maxOrThrow()
extension functionoday
03/14/2019, 1:31 PM