Adam H
Adam H

Reputation: 741

Scala - tuple3 - syntactic sugar

What is the syntactic sugar equivalent of following syntax:

List[Tuple2[String, Int]]  // Base
List[String Tuple2 Int]  // Syntactic sugar

for Tuple3? E.g.:

List[Tuple3[String, Float, Int]]  // Base

Upvotes: 4

Views: 3478

Answers (1)

Jörg W Mittag
Jörg W Mittag

Reputation: 369420

This makes no sense. Infix syntax by definition works only for arity 2. That's not something special to Scala, that's not even special to programming, that's how it has always been and how it will always be. Infix operators are called infix operators because they sit in between their two operands. How can one operator sit in between three operands? You would need a two-part operator to sit in the two spaces between the three operands. Such operators do exist, they are called ternary operators, but it's not quite trivial to devise a syntax for using them interchangeably with prefix syntax, like Scala does.

Note, however, that there is syntactic sugar for what you are asking about:

List[Tuple2[String, Int]]  // Base
List[(String, Int)]  // Syntactic sugar

List[Tuple3[String, Float, Int]]  // Base
List[(String, Float, Int)]  // Syntactic sugar

Upvotes: 11

Related Questions