Tuesday, September 2, 2014

Tuples


let coord = (3, 5)

or

let coord:(Int, Int) = (3, 5)
//playground result:(.0 3, .1 5)


//To access elements of the tuple:
coord.0 //3
coord.1 //5

or

let (x, y) = coord
//3
//5

or use underscores to ignore elements of the tuple:

let (_,theYvalue) = coord

theYvalue //5



Named tuple

let coord = (X: 3, Y: 5)

coord.X //3
coord.Y //5

or the explicit form:

let coord:(myX:Int, myY:Int) = (3, 5)

coord.myX //3
coord.myY //5

No comments:

Post a Comment