![]() ![]() ![]() I often prefer to assign them to variables using pattern matching: You can access tuple elements using an underscore construct: T: (Int,, Person) = (3,Three,Person(Al)) Scala> val t = (3, "Three", new Person("Al")) The following example shows a three-element tuple: Notice that it contains two different types. SolutionĪ tuple gives you a way to store a group of heterogeneous items in a container, which is useful in many situations.Ĭreate a tuple by enclosing the desired elements between parentheses. When writing a Scala application, you want to create a small collection of heterogeneous elements. This is Recipe 10.27, “Scala Tuples, for When You Just Need a Bag of Things” Problem This is an excerpt from the 1st edition of the Scala Cookbook (partially modified for the internet).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |