It seems there is not in Kotlin infix function wit...
# getting-started
v
It seems there is not in Kotlin infix function without parameters. I mean, we can not in some way implement something like: fun main() { println(1 m) } infix fun Number.m() = Meter(this.toDouble()) class Meter(val value: Double) Or exist some trick?
j
You cannot have it infix, but usually what we do is use an extension property instead:
Copy code
val Number.m: Meter
    get() = Meter(this.toDouble())
And the use it like
1.m
3
r
As a side note, infix by definition requires something on either side. What you're talking about would be a postfix (or suffix) function.
3
v
Yes, you are right. I just wanted to check to be on the safe side. As far as I understand, there are no plans to implement suffix and postfix functions in Kotlin at the moment. See for example https://discuss.kotlinlang.org/t/suffix-notation/1369/9