```myMutableInt = myMutableInt + 2``` can be simpl...
# announcements
l
Copy code
myMutableInt = myMutableInt + 2
can be simplified to
Copy code
myMutableInt += 2
but is there any way to do something similar with non-operator functions, e.g. simplifying
Copy code
myMutableInt = myMutableInt.coerceIn(10, 100)
to something like
Copy code
myMutableInt .= coerceIn(10,100) //not valid syntax
?
i
.=
operator does not exist in Kotlin.
l
yes, thats exactly what my comment says.
i
I think you may introduce an infix function.
Like
myMutableInt coerceIn (10 to 100)
However, there is no way to override any form of reassignment.
l
so i take it that what i am looking for doesnt exist ?
i
I think yes.
l
alright ty
i
I know only one language that allows to create custom operators
a
Cpp?
e
but, you can't overwrite variable like pointer.
i
@andylamax ML
In C++ you only can overload operators' behavior