2018-07-16 14:05:25 +00:00
|
|
|
// sole member of the Unit type (like C/Java void).
|
|
|
|
() //(empty parens)
|
|
|
|
|
|
|
|
// tuple literal
|
|
|
|
// This example would be a Tuple3
|
2017-05-28 21:10:53 +00:00
|
|
|
(1,2,3)
|
|
|
|
|
2018-07-16 14:05:25 +00:00
|
|
|
// tuple sugar
|
|
|
|
// This example would be a Tuple2
|
2018-07-13 15:07:30 +00:00
|
|
|
(1 -> 2) //same as
|
|
|
|
(1, 2)
|
|
|
|
|
2017-05-28 21:10:53 +00:00
|
|
|
// destructuring bind: tuple unpacking via pattern matching.
|
|
|
|
var (x,y,z) = (1,2,3)
|
|
|
|
|
|
|
|
// hidden error: each assigned to the entire tuple.
|
|
|
|
// BAD
|
|
|
|
var x,y,z = (1,2,3)
|
|
|
|
|
|
|
|
// list (immutable).
|
|
|
|
var xs = List(1,2,3)
|
|
|
|
|
|
|
|
// paren indexing. (slides)
|
|
|
|
// more on it: https://www.slideshare.net/Odersky/fosdem-2009-1013261/27
|
|
|
|
xs(2)
|
|
|
|
|
2018-07-16 14:05:25 +00:00
|
|
|
// cons.
|
|
|
|
1 :: List(2,3)
|
|
|
|
|
2018-07-13 15:07:30 +00:00
|
|
|
// map (Immutable)
|
|
|
|
Map(1 -> 'a', 2 -> 'b', 3 -> 'c') //same as
|
|
|
|
Map((1, 'a'), (2, 'b'), (3, 'c'))
|
|
|
|
|
2018-07-16 14:05:25 +00:00
|
|
|
// range
|
|
|
|
// accepts start, end and step parameters
|
|
|
|
Range(1, 5) //returns Range(1,2,3,4,5)
|
|
|
|
Range(1, 10, 2) //returns Range(1,3,5,7,9)
|
2017-05-28 21:10:53 +00:00
|
|
|
|
|
|
|
// range sugar.
|
|
|
|
1 to 5 // same as
|
|
|
|
1 until 6
|
|
|
|
1 to 10 by 2
|