mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 15:53:46 +00:00
27 lines
525 B
Kotlin
Vendored
27 lines
525 B
Kotlin
Vendored
// IGNORE_BACKEND_FIR: JVM_IR
|
|
// IGNORE_BACKEND: NATIVE
|
|
// MODULE: lib
|
|
// 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) }
|
|
}
|
|
|
|
// MODULE: main(lib)
|
|
// FILE: main.kt
|
|
fun box(): String {
|
|
var result = false
|
|
tryCatch(block = { true }) {
|
|
result = it
|
|
}
|
|
return if (result) "OK" else "Fail"
|
|
}
|