Created
February 12, 2019 07:37
-
-
Save hkurokawa/315dae5926c9a659eb9fa43b26d89276 to your computer and use it in GitHub Desktop.
Kotlin Contracts sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.InvocationKind | |
import kotlin.contracts.contract | |
class Foo { | |
fun foo() {} | |
} | |
@ExperimentalContracts | |
inline fun Foo.bar(block: Foo.() -> Unit) { | |
contract { | |
callsInPlace(block, InvocationKind.AT_LEAST_ONCE) | |
} | |
block() | |
this.foo() | |
} | |
@ExperimentalContracts | |
fun hoge(): Int { | |
Foo().bar { | |
return 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment