The conventional expectation of operators that end with =
, such as +=
, -=
, *=
, and so on, is
that the result of the operation will be assigned to the operand on the left-hand side of the operator.
Define any other behavior and you almost guarantee that the users of your code will misunderstand and therefore misuse your operator.
Noncompliant code example
func **= (p1:Int, p2:Int) -> Int { // Noncompliant. Change operator name or update value of first parameter
return p1 ** p2
}
func => (p1:Int, p2:Int) -> Int { // Compliant; doesn't end with '='
return p1 ** p1 ** p2
}
Compliant solution
func **= (inout p1:Int, p2:Int) {
p1 = p1 ** p2
}
func => (p1:Int, p2:Int) -> Int {
return p1 ** p1 ** p2
}