Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Last active December 17, 2021 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/732ba1d45e45898fa19d6911dffd5c84 to your computer and use it in GitHub Desktop.
Save magdamiu/732ba1d45e45898fa19d6911dffd5c84 to your computer and use it in GitHub Desktop.
inline and noinline modifiers | High performance with idiomatic Kotlin
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