scalatuples

Does Scala have syntax for 0- and 1-tuples?


scala> val two = (1,2)
two: (Int, Int) = (1,2)

scala> val one = (1,)
<console>:1: error: illegal start of simple expression
       val one = (1,)
                    ^

scala> val zero = ()
zero: Unit = ()

Is this:

val one = Tuple1(5)

really the most concise way to write a singleton tuple literal in Scala? And does Unit work like an empty tuple?

Does this inconsistency bother anyone else?


Solution

  • really the most concise way to write a singleton tuple literal in Scala?

    Yes.

    And does Unit work like an empty tuple?

    No, since it does not implement Product.

    Does this inconsistency bother anyone else?

    Not me.