Tuples Are
- Not collections but finite heterogeneous containers
- case classes parameterized in each field
- Standard library contains Tuple1 to Tuple22
Tuple fields are created as _1,_2 etc
Tuples 2s pairs can be created with -> operator
scala> Tuple2(1,"a")
res41: (Int, String) = (1,a)
scala> Tuple2(1,2)
res42: (Int, Int) = (1,2)
scala> (1,"a")
res44: (Int, String) = (1,a)
scala> val pair = (1,"a")
pair: (Int, String) = (1,a)
scala> pair._2
res45: String = a
scala> 1->"a"
res46: (Int, String) = (1,a)
- Not collections but finite heterogeneous containers
- case classes parameterized in each field
- Standard library contains Tuple1 to Tuple22
Tuple fields are created as _1,_2 etc
Tuples 2s pairs can be created with -> operator
scala> Tuple2(1,"a")
res41: (Int, String) = (1,a)
scala> Tuple2(1,2)
res42: (Int, Int) = (1,2)
scala> (1,"a")
res44: (Int, String) = (1,a)
scala> val pair = (1,"a")
pair: (Int, String) = (1,a)
scala> pair._2
res45: String = a
scala> 1->"a"
res46: (Int, String) = (1,a)
No comments:
Post a Comment