7ab2f1493c
To compile standard library code that uses error()
46 lines
988 B
Kotlin
Vendored
46 lines
988 B
Kotlin
Vendored
package kotlin
|
|
|
|
import kotlin.*
|
|
|
|
public inline fun <R> run(block: () -> R): R {
|
|
return block()
|
|
}
|
|
|
|
public inline fun <T, R> T.run(block: T.() -> R): R {
|
|
return block()
|
|
}
|
|
|
|
public inline fun <T, R> with(receiver: T, block: T.() -> R): R {
|
|
return receiver.block()
|
|
}
|
|
|
|
public inline fun <T> T.apply(block: T.() -> Unit): T {
|
|
block()
|
|
return this
|
|
}
|
|
|
|
public inline fun <T> T.also(block: (T) -> Unit): T {
|
|
block(this)
|
|
return this
|
|
}
|
|
|
|
public inline fun <T, R> T.let(block: (T) -> R): R {
|
|
return block(this)
|
|
}
|
|
|
|
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? {
|
|
return if (predicate(this)) this else null
|
|
}
|
|
|
|
public inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T? {
|
|
return if (!predicate(this)) this else null
|
|
}
|
|
|
|
public inline fun repeat(times: Int, action: (Int) -> Unit) {
|
|
for (index in 0 until times) {
|
|
action(index)
|
|
}
|
|
}
|
|
|
|
public inline fun error(message: Any): Nothing = throw IllegalStateException(message.toString())
|