Added tuples

This commit is contained in:
George Petrov 2013-07-31 20:52:59 +01:00
parent 49ee527a79
commit 38bd9a18fd

View File

@ -92,6 +92,26 @@ s(1)
// Tuples
(1, 2)
(4, 3, 2)
(1, 2, "three")
(a, 2, "three")
// Why have this?
val divideInts = (x:Int, y:Int) => (x / y, x % y)
divideInts(10,3) // The function divideInts gives you the result and the remainder
// To access the elements of a tuple, use _._n where n is the 1-based index of the element
val d = divideInts(10,3)
d._1
d._2
// Combinators