Skip to content

Instantly share code, notes, and snippets.

@lecuseasar
Last active July 10, 2022 18:45
Show Gist options
  • Save lecuseasar/4a371200c7757f40e6f3b57c37a3b766 to your computer and use it in GitHub Desktop.
Save lecuseasar/4a371200c7757f40e6f3b57c37a3b766 to your computer and use it in GitHub Desktop.
Kotlin Extension and Infix Functions
fun main() {
println(5.triple())
val list = mutableListOf("emre", "pbu", "arg")
list.swap(0, 1)
println(list)
println(5.topla(1))
println(5 topla 1)
println(list[0].birlestir(list[1]))
}
fun Int.triple() = this * 3
fun MutableList<String>.swap(firstIndex: Int, secondIndex: Int) {
val temp = this[firstIndex]
this[firstIndex] = this[secondIndex]
this[secondIndex] = temp
}
infix fun Int.topla(value: Int): Int = this + value
infix fun String.birlestir(str: String): String = this + str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment