Book Image

Professional Scala

By : Mads Hartmann, Ruslan Shevchenko
Book Image

Professional Scala

By: Mads Hartmann, Ruslan Shevchenko

Overview of this book

This book teaches you how to build and contribute to Scala programs, recognizing common patterns and techniques used with the language. You’ll learn how to write concise, functional code with Scala. After an introduction to core concepts, syntax, and writing example applications with scalac, you’ll learn about the Scala Collections API and how the language handles type safety via static types out-of-the-box. You’ll then learn about advanced functional programming patterns, and how you can write your own Domain Specific Languages (DSLs). By the end of the book, you’ll be equipped with the skills you need to successfully build smart, efficient applications in Scala that can be compiled to the JVM.
Table of Contents (12 chapters)

Other Collections


Now that we've covered the List and some relevant Traversables in the Scala standard library, we should also visit some other useful collections Scala provides. Even though this section has less theoretical material, this means that we'll have more time on the final activities of the chapter.

Sets

Sets are Iterables that contain no duplicate elements. The Set class provides methods to check for the inclusion of an element in the collection, as well as combining different collections. Note that since Set inherits from Traversable, you can apply all the higher-order functions we've seen previously on it. Due to the nature of its apply method, a Set can be seen as a function of type A => Boolean, which returns true if the element is present in the set, and false otherwise.

Tuples

A tuple is a class capable of containing an arbitrary number of elements of different types. A tuple is created by enclosing its elements in parentheses. A tuple is typed according...