Kotlin Q & A

 

How do you define an infix function in Kotlin?

To define an infix function in Kotlin, you simply add the infix modifier before the fun keyword in the function declaration. The function must have exactly one parameter, and it can be either a member function or an extension function.

Here’s the general syntax for defining an infix function:/

kotlin

infix fun Type.functionName(parameter: Type): ReturnType {
 // Function body
}

Once defined, you can use the infix function with infix notation, allowing for more readable and expressive code.

Previously at
Flag Argentina
Brazil
time icon
GMT-3
Experienced Android Engineer specializing in Kotlin with over 5 years of hands-on expertise. Proven record of delivering impactful solutions and driving app innovation.