This allows conditional operations on the collection, or for code to determine the size of the collection, including whether it's infinite or discrete. Size info - isEmpty, nonEmpty, size, and hasDefiniteSize are all metadata about the set.Val array: Array = List(1, 2, 3).toArray // convert list of ints to array of ints These are usually methods prepended with 'to' and the more specific type (i.e. Conversions - toList, toArray, and many other conversion operations change the current collection into a more specific kind of collection.split list of letters into individual strings and put them into the same list Map - map, flatMap, and collect produce new collections by applying a function to each element in the original collection.The most common operations are listed here: Traversable typesĬollection classes that have the Traversable trait implement foreach and inherit many methods for performing common operations to collections, which all function identically. Vector can be used wherever List is used. It is now a best-practice to use Vector instead of List because the implementations have better performance Performance characteristics can be found here. These like-minded types inherit from the Traversable trait. For example, summing all elements in a collection is the same for Lists, Sets, Vectors, Seqs and Arrays: val numList = List(1, 2, 3, 4, 5) One of the most powerful features of the framework is the consistent and easy-to-use interface across like-minded collections. Constructing a List() (without importing anything) will construct an immutable list. By default, the immutable versions are used. These built-in collections are separated into the immutable and mutable packages. For more information on these building blocks, read the official Scala collections overview. The framework is made up of Scala traits that are designed to be building blocks for creating collections. The Scala Collections framework, according to its authors, is designed to be easy to use, concise, safe, fast, and universal. Single Abstract Method Types (SAM Types).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |