Real life examples of Scala infix types

后端 未结 3 1929
南方客
南方客 2021-01-03 06:36

I\'ve found one interesting syntax stuff. It\'s called Infix type.

Example:

class M[T, U]
new (Int M String)

And now I

3条回答
  •  我在风中等你
    2021-01-03 07:08

    In scala library there is a class named ::. It is used so you could match the list like this:

    def m(l : List[Int]) = l match {
      case a :: b => println("Matched")        // The same as case ::(a, b) => ...
      case _ => println("Not matched")
    }
    

    There are lots of other examples in libraries like scalaz I think, but this one is the most canonical.

    Updated

    Just understood that it is not exactly what you wanted - you wanted types. Was adding =:= and <:< to the answer, but @johny was faster. Please see his answer

提交回复
热议问题