Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - tuple3 - syntactic sugar

Tags:

tuples

scala

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
like image 555
Adam H Avatar asked Dec 18 '22 22:12

Adam H


1 Answers

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
like image 165
Jörg W Mittag Avatar answered Jan 01 '23 22:01

Jörg W Mittag