Mutare.Mutators.OperandSwap (mutare v0.4.1)

Copy Markdown View Source

Reverses the first two operands of non-commutative operators and calls.

Operators

  • -, /, and **
  • <>
  • ++ and --
  • div, rem — integer division / remainder.

The operator is retained; only the operands are exchanged.

The following operators are excluded:

  • >, >=, <, and <=, because Mutare.Mutators.Relational already produces the equivalent direction change
  • commutative operators such as +, *, equality, and boolean operators
  • in, because the swapped right operand may not be enumerable
  • = and |>, whose operands have different roles

Calls

The first two arguments are exchanged in these calls:

A trailing unit in diff/3 is retained and may be mutated separately by Mutare.Mutators.ModeSwap.

Aliased and imported calls are supported. An alias that resolves to another module does not match.

Piped calls

A pipe stage is the call it is sugar for, so its piped value is the first operand and the transpose moves it:

foo |> Kernel.++(bar)  →  bar |> Kernel.++(foo)

This is how a pipe expresses an operator, so the explicit Kernel call forms (Kernel.++, Kernel.-, Kernel.<>, Kernel.div, …) are transposed like the operators they name, written directly or piped.

Skipped cases

Identical operands are not swapped. Unary minus has no second operand and is handled by Mutare.Mutators.Arithmetic.

Guard-safe operators and calls are also mutated in guards.