also shows how to override the accessor and mutator methods that Scala automatically
generates for your val and var variables. Several recipes show what case classes are and
how to use them, and how to write equals methods.
Chapter 5, Methods, shows how to define methods to accept parameters, return values,
use parameter names when calling methods, set default values for method parameters,
create varargs fields, and write methods to support a fluent style of programming.
Chapter 6, Objects, covers “all things object.” Like Java, Scala uses the word object to
refer to an instance of a class, but Scala also has an object keyword. This chapter covers
topics like class casting, how to launch an application with an object, how to create the
equivalent of Java’s static members, and how to write a class with a companion object
so you can create new instances of a class without using the new keyword.
Chapter 7, Packaging and Imports, provides examples of Scala’s package and import
statements, which provide more capabilities than the same Java keywords. This includes
how to use the curly brace style for packaging, how to hide and rename members when
you import them, and more.
Chapter 8, Traits, provides examples of the Scala trait. It begins by showing how to use
a trait like a Java interface, and then gets into more advanced topics, such as how to use
traits as “mixins,” and limit which members a trait can be mixed into using a variety of
methods.
Although much of the book demonstrates functional programming (FP) techniques,
Chapter 9, Functional Programming, combines many FP recipes into one location. Sol‐
utions show how to define anonymous functions (function literals) and use them in a
variety of situations. Recipes demonstrate how to define a method that accepts a func‐
tion argument, how to return a function from a function, and how to use closures and
partially applied functions.
The Scala collections library is rich and deep, so Chapter 10, Collections, and Chapter 11,
List, Array, Map, Set (and More), provide more than 100 pages of collection-related
solutions.
Recipes in Chapter 10, Collections, help you choose collection classes for specific needs,
and then help you choose and use methods within a collection to solve specific problems,
such as transforming one collection into a new collection, filtering a collection, and
creating subgroups of a collection. More than 60 pages of recipes demonstrate solutions
for writing for loops, for/yield expressions, using methods like filter, foreach,
groupBy, map, and many more.
Chapter 11, List, Array, Map, Set (and More), continues where Chapter 10, Collections,
leaves off, providing solutions for those specific collection types, as well as recipes for
the Queue, Stack, and Range classes.
xviii | Preface
www.it-ebooks.info