Map() also uses that variable argument syntax we learned back in Lesson #1: Map(1 -> "one", 2 -> "two") which expands into Map((1, "one"), (2, "two")) with the first element being the key and the second being the value of the Map. This looks like special syntax but remember back to our discussion of Tuple that -> can be used to create Tuples. See Also Effective Scala has opinions about destructuring bindings (“unpacking” a tuple). Tuple has some special sauce for simply making Tuples of 2 values: -> Unlike case classes, they don’t have named accessors, instead they have accessors that are named by their position and is 1-based rather than 0-based. HostPort: (String, Int) = (localhost, 80) Numbers: = Set(5, 1, 2, 3, 4)Ī tuple groups together simple logical collections of items without using a class. Sets do not preserve order and have no duplicates :9: error: value update is not a member of List Lists preserve order, can contain duplicates, and are immutable. ArraysĪrrays preserve order, can contain duplicates, and are mutable. See Also Effective Scala has opinions about how to use collections.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |