diff options
author | George Petrov <petrovg@gmail.com> | 2013-07-31 20:52:59 +0100 |
---|---|---|
committer | George Petrov <petrovg@gmail.com> | 2013-07-31 20:52:59 +0100 |
commit | 38bd9a18fda39e70060cd64a49a0095ba4901e26 (patch) | |
tree | 8670fdbf6a9ebc1c82d6dfff1aaeef5235b65c2b /scala.html.markdown | |
parent | 49ee527a79adbe3fde50b71effb4a9340b7ab7dc (diff) |
Added tuples
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 20 |
1 files changed, 20 insertions, 0 deletions
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 |