Last active
December 17, 2021 10:39
-
-
Save magdamiu/732ba1d45e45898fa19d6911dffd5c84 to your computer and use it in GitHub Desktop.
inline and noinline modifiers | High performance with idiomatic Kotlin
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
inline fun computeValues( | |
number: Int, doubleValue: (number: Int) -> Unit, | |
noinline tripleValue: (number: Int) -> Unit) { | |
doubleValue.invoke(number) | |
tripleValue.invoke(number) | |
} | |
fun main() { | |
val number = 7; | |
computeValues(number, | |
{ println(doubleOfNumber(number)) }, | |
{ println(tripleOfNumber(number)) }) | |
} | |
fun doubleOfNumber(number: Int) = 2 * number | |
fun tripleOfNumber(number: Int) = 3 * number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment