`.takeIf { ... }` makes me think it might be usefu...
# stdlib
k
.takeIf { ... }
makes me think it might be useful to have a
.orElse { ... }
or similar that is basically a function version of the Elvis operator. Would be useful if you're chaining more methods afterwards because with an Elvis, you'd have to wrap the expression from the very start up to after the Elvis in parens, which can get kind of messy Kind of a contrived example, but:
Copy code
val lastTransactionId = api.getUser("userId")
    .takeIf { it.transactions.isNotEmpty() }
    .orElse { error("user has no transactions") }
    .transactions.last.id
vs
Copy code
val lastTransactionId = (api.getUser("userId")
    .takeIf { it.transactions.isNotEmpty() }
    ?: error("user has no transactions"))
    .transactions.last.id
Thoughts?