mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-26 23:23:55 +00:00
Added tuples
This commit is contained in:
parent
49ee527a79
commit
38bd9a18fd
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user