Scala factorial method (that is "!") : removing the dot operator?

implicit-conversion, scala

Solution

Just `import language.postfixOps`:

import language.postfixOps
implicit class IntegerUtils(wrapped:Int) {
  def !() = (2 to wrapped).product
}

(1 to 5).foreach { v => println (v!) }            //> 1
                                                  //| 2
                                                  //| 6
                                                  //| 24
                                                  //| 120

As the docs note, "Postfix operators interact poorly with semicolon inference. Most programmers avoid them for this reason." But if you're doing a lot of this in a particular file, it can be very handy.

Problem

I managed to define a new operator for Integer in scala : the "!" factorial operator. Meanwhile, I would like to call it without the dot operator, such that no warning is thrown (and I don't want to disable warning feature). Is it possible ? This is my test code : implicit.scala ``` implicit class IntegerUtils(wrapped:Int) { def !() = (2 to wrapped).product } (1 to 5).foreach { v => println (v.!) } ```

Original source