From 38bd9a18fda39e70060cd64a49a0095ba4901e26 Mon Sep 17 00:00:00 2001 From: George Petrov Date: Wed, 31 Jul 2013 20:52:59 +0100 Subject: Added tuples --- scala.html.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scala.html.markdown b/scala.html.markdown index b22ba15b..8bcb5975 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -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 -- cgit v1.2.3