``` fun foo(bar: List<Int>): Int { check...
# codereview
a
Copy code
fun 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?
w
If
foo
is fine to thrown exception (as I suspect based on the
check
), you can do something like:
Copy code
fun foo(bar: List<Int>): Int =
        bar
                .max()
                ?.let { it / 2 }
                ?: throw Exception("foo failed")
m
You can use
error("foo failed")
instead of
throw Exception
👍 1
p
I have written
.maxOrThrow()
extension function
👍 1
o
^^
steal from him