Last active
August 30, 2018 09:15
-
-
Save adibfara/7f860ac6870a5cb1629ec0bbf86d30bb to your computer and use it in GitHub Desktop.
This file contains 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.contract | |
/** | |
* @author Adib Faramarzi (adibfara@gmail.com) | |
*/ | |
@ExperimentalContracts | |
fun createOnce(runFunction: ()-> Unit) { | |
contract { | |
callsInPlace(runFunction, kotlin.contracts.InvocationKind.EXACTLY_ONCE) | |
} | |
runFunction() | |
} | |
@ExperimentalContracts | |
fun getKotlinVersion(): Float{ | |
val kotlinVersion: Float | |
createOnce { | |
kotlinVersion = 1.3f | |
} | |
// no compile error! | |
return kotlinVersion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment