Coming from scala miss so much tuples when working...
# language-proposals
u
Coming from scala miss so much tuples when working on kotlin, has there been disscussions about it? Scala also added support for named tuples which are the lambdas (annonymous/structural) counterpart for data classes instead of named/nominal, so they can be used as structural data types, while still being plain tuples as tuple names are erased
plus1 1
a
I'd actually love to hear about your use cases 🙂 • when do you use tuples? • how do you decide between using a tuple vs. a small case class? • how long are the tuples you use? (Kotlin stdlib comes with Pair and Triple, do you miss more?)
u
> When do you use tuples? • Tuples are used for fixed size, index safe random access, they are also non-class collections alternative to
Pair
,
Triple
example on chessboard grid which is 8x8 would use
Tuple8
> Tuples VS case class • For library authors, tuples could be used without importing classes like Pair , Triple, for the case on names tuples they can entirely replace any case or data class example: •
typealias Point = (x:float, y: float)
• Tuples are also used on
map
,
flatMap
streams to generate next chain data • Named tuples on scala where also pushed to improve scala-sql mappings as names tuples can be generated on the fly, same can be said for a kotlin/ktor compiler plugin > How long are tuples? Longest tuple has been of size 8 for chess/checker board rows/columns
thank you color 1
👍 1