throwfold
Syntax-sugar for a lambda folds a potentially Throwable receiver type into type Out.
This function does not catch exceptions.
val result: Throwable = IllegalStateException()
// Before:
(result as? Throwable)?.let { "$it" } ?: "The world is good!"
// After:
result.throwfold(throws = { "$it" }, pass = { "The world is good!" })
Content copied to clipboard