Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Programming in Scala > Chapter 24: The Scala Collections API - Pg. 497

Chapter 24 The Scala Collections API In the eyes of many, the new collections framework is the most significant change in Scala 2.8. Scala had collections before (and in fact the new frame- work is largely compatible with them). But it's only 2.8 that provides a common, uniform, and all-encompassing framework for collection types. Even though the additions to collections are subtle at first glance, the changes they can provoke in your programming style can be profound. In fact, quite often it's as if you work on a higher level with the basic building blocks of a program being whole collections instead of their elements. This new style of programming requires some adaptation. Fortunately, the adap- tation is helped by several nice properties of the new Scala collections. They are easy to use, concise, safe, fast, and universal. Easy to use: A small vocabulary of twenty to fifty methods is enough to solve most collection problems in a couple of operations. No need to wrap your head around complicated looping structures or recur- sions. Persistent collections and side-effect-free operations mean that you need not worry about accidentally corrupting existing collections with new data. Interference between iterators and collection updates is eliminated. Concise: You can achieve with a single word what used to take one or sev- eral loops. You can express functional operations with lightweight syntax and combine operations effortlessly, so that the result feels like a custom algebra. Safe: This one has to be experienced to sink in. The statically typed and functional nature of Scala's collections means that the overwhelming 497