페이지

2015년 10월 27일 화요일

Scala2e Chapter3 Next Steps in Scala - Step 9. Use tuples

Tuples are immutable.
Tuples can contain different type of elements.

val pair = (99, "Luftballons")
println(pair._1)
println(pair._2)

apply method always retuns the same type, but each element of a tuple may be a different type: _1 can have one result type, _2 another, and so on.
These _N numbers are one-based, instead of zero-base, because string with 1 is a tradition set by other lanaguages with statically typed tuples, such as Haskell and ML.



댓글 없음: