`return foo?.let { doStuff(it, bar, baz) } ?: fals...
# getting-started
s
return foo?.let { doStuff(it, bar, baz) } ?: false
🙌 2
s
Thanks, I figured there was some way to use an elvis operator here.
👍 1
a
personally, I like to avoid let when i can, by returing early when foo evaluates to null:
Copy code
fun myThing() {
    val foo = getFoo() ?: return false
    return doStuff(foo, bar, baz)
}
👍 3
That way the preconditions are explicit and handled beforehand, and the actual logic is not stowed away inside an extra scope.