blob: 791f6b3395bad7ac00f8e1048804b2e9d3d55116 [file] [log] [blame]
// FILE: lib.kt
inline fun <T> T.andAlso(block: (T) -> Unit): T {
block(this)
return this
}
inline fun <T> tryCatch(block: () -> T, onSuccess: (T) -> Unit) {
try {
block()
} catch (e: Throwable) {
return
}.andAlso { onSuccess(it) }
}
// FILE: main.kt
fun box(): String {
var result = false
tryCatch(block = { true }) {
result = it
}
return if (result) "OK" else "Fail"
}