Tuple
scala> :paste // Entering paste mode (ctrl-D to finish) val t1 = (1, 2) val t2 = 1 -> 2 val t3 = 1 → 2 val t4 = Tuple2(1,2) val t5 = Pair(1, 2) val t6 = Triple(1, 2, 3) // Exiting paste mode, now interpreting. <pastie>:15: warning: object Pair in object Predef is deprecated (since 2.11.0): use built-in tuple syntax or Tuple2 instead val t5 = Pair(1, 2) ^ <pastie>:16: warning: object Triple in object Predef is deprecated (since 2.11.0): use built-in tuple syntax o r Tuple3 instead val t6 = Triple(1, 2, 3) ^ t1: (Int, Int) = (1,2) t2: (Int, Int) = (1,2) t3: (Int, Int) = (1,2) t4: (Int, Int) = (1,2) t5: (Int, Int) = (1,2) t6: (Int, Int, Int) = (1,2,3)
Pair
とTriple
は2.11.0
から非推奨だって
Play Framework2.8ではScala 2.11のサポートが終了するのでもうこいつらは忘れていい、さようなら
t1
(1, 2)
は(1 -> 2)
の糖衣構文
t2, t3
/** @group implicit-classes-any */ implicit final class ArrowAssoc[A](private val self: A) extends AnyVal { @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(self, y) def →[B](y: B): Tuple2[A, B] = ->(y) }
t5, t6
Predef
type Pair[+A, +B] = Tuple2[A, B] type Triple[+A, +B, +C] = Tuple3[A, B, C]
t4
ただのTuple2オブジェクト
Scala Standard Library 2.13.1 - scala.Tuple2
最大22まで標準搭載
Scala Standard Library 2.13.1 - scala.Tuple22
23は要素多いすぎエラー
タプルってことは認識されてるようだ
scala> val t = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) <console>:1: error: too many elements for tuple: 23, allowed: 22 val t = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) ^
Tuple1
Scala Standard Library 2.13.1 - scala.Tuple1
型指定すればつかえる、どこで使うのかはしらん
scala> :paste // Entering paste mode (ctrl-D to finish) val t = (1) val t1 = Tuple1(1) // Exiting paste mode, now interpreting. t: Int = 1 t1: (Int,) = (1,)