DEV Community

Discussion on: Write a function that shows off something unique or interesting about the language you're using

Collapse
 
chrisvasqm profile image
Christian Vasquez • Edited

Kotlin has this concept of infix functions, which means they are an extension function that has only 1 parameter and allows us to use them without the dot (.) operator and no parentheses (but you can also do it the normal way, if you want to).

Declare the infix function

infix fun Int.times(base: Int) = this * base

Example

fun main(args: Array<String>) {
    println(10 times 5)  // prints 50
    println(10.times(5)) // also prints 50
}