Chapter 1. Scala—a blended language
Listing 1.1. Byte conversions in scala.Predef object
Chapter 2. The core rules
Listing 2.1. Companion objects in REPL
Listing 2.2. Correct companion object in REPL
Listing 2.3. Inexpressible language features in the REPL
Listing 2.4. Java idiom: one return statement
Listing 2.5. Updated createErrorMessage with expression-oriented pattern match
Listing 2.6. Final expression-oriented createErrorMessage method
Listing 2.7. Example of imperative style code
Listing 2.8. Example mutable expression-oriented method
Listing 2.9. Mixing immutable and mutable objects with expression
Listing 2.10. Mutable objects and expressions—the right way
Listing 2.11. Mutable Point2 class
Listing 2.12. Mutable Point2 class with hashing function
Listing 2.13. Mutable Point2 class with hashing and equality
Listing 2.14. Mutating Point2 with HashMap
Listing 2.15. Simple usage of Some and None
Listing 2.16. Usage of the Option factory
Listing 2.17. Creating an object or returning a default
Listing 2.18. Executing code if option is defined
Listing 2.19. Executing code if several options are defined
Listing 2.21. Generically converting functions
Listing 2.22. Simple InstantaneousTime class
Listing 2.23. Event subclass of InstantaneousTime
Listing 2.24. Using Event and InstantaneousTime
Chapter 3. Modicum of style—coding conventions
Listing 3.1. Next line opening brackets causing issues
Listing 3.2. Next line opening brackets compiling correctly
Listing 3.3. Using dangling operators
Listing 3.4. Using parentheses
Listing 3.5. Simple method to calculate an average
Listing 3.6. Average.scala file with mischievous class
Listing 3.7. Average.scala with mischievous inner classes
Listing 3.8. Simple named parameter usage
Listing 3.9. Named parameters and inheritance
Listing 3.10. Changing the underlying method
Listing 3.11. Traits won’t cause compile errors
Listing 3.12. Traits will cause compile errors
Listing 3.13. Animal hierarchy with override
Listing 3.14. Multiple inheritance and override
Listing 3.15. Animal hierarchy without override
Listing 3.16. Multiple inheritance without override
Chapter 4. Utilizing object orientation
Listing 4.1. Poor Hello World! example in Scala
Listing 4.2. Application trait
Listing 4.3. SimulationEntity class
Listing 4.4. NetworkEntity trait
Listing 4.5. Empty implementation trait attempt
Listing 4.6. REPL session with simulation classes
Listing 4.7. Composition of Logger and DataAccess classes
Listing 4.8. Composition of Logger and DataAccess into third class
Listing 4.9. Inheritance-based composition of Logger and DataAccess
Listing 4.10. Logger hierarchy
Listing 4.11. Abstract member-composition trait HasLogger
Listing 4.12. DataAccess class with HasLogger trait
Listing 4.13. Specification test for DataAccess
Listing 4.14. DataAccess as a class with default arguments
Listing 4.15. Inheritance with default arguments
Listing 4.16. Simple Scala trait and implementation class
Listing 4.17. javap disassembly of Main class
Listing 4.18. Modified Foo trait
Listing 4.19. ScalaMain testing class
Listing 4.20. Modified ScalaMain testing class
Listing 4.21. PureAbstract trait
Listing 4.22. MessageDispatcher trait
Listing 4.23. MessageDispatcher factory and implementation class
Listing 4.24. MessageDispatcher factory with two implementation classes
Chapter 5. Using implicits to write expressive code
Listing 5.1. externalbindings.scala
Listing 5.2. Implicit binding test file
Listing 5.5. Inline definitions
Listing 5.6. Companion object and implicit lookup
Listing 5.7. Simple Matrix class
Listing 5.8. Matrix multiplication
Listing 5.9. Concurrent strategey
Chapter 6. The Type System
Listing 6.1. Defining types from class, trait, or object keywords
Listing 6.2. Path-dependent types and type projection examples
Listing 6.3. Resource handling utility
Listing 6.4. Nested structural typing
Listing 6.5. Path-dependent and structural types
Listing 6.6. Lower bounds on types
Listing 6.7. Upper bounds on types
Listing 6.8. Covariance example
Listing 6.9. Implicit variance of methods
Listing 6.10. First attempt at defining a function object
Listing 6.11. Function object with only covariance
Listing 6.12. Function with covariance and contravariance
Listing 6.13. Complete function example
Listing 6.14. First attempt at a list interface
Listing 6.15. Naive attempt to work around variance
Chapter 7. Using implicits and types together
Listing 7.2. TraversableOnce.sum method
Listing 7.3. Initial FileLike interface
Listing 7.4. File synchronization using FileLike
Listing 7.5. Enforcing To/From types with type arguments
Listing 7.6. Higher-kinded FileLike
Listing 7.7. FileLike type class trait
Listing 7.8. Synchronize method using type class
Listing 7.9. Creating default type class implementation for java.io.File
Chapter 9. Actors
Listing 9.1. Supervisor for search nodes
Listing 9.2. SearchTree factory
Listing 9.3. AdaptiveSearchNode
Listing 9.4. LeafNode.executeLocalQuery
Listing 9.5. LeafNode.addDocumentToLocalIndex
Chapter 10. Integrating Scala with Java
Chapter 11. Patterns in functional programming
Listing 11.1. Functor typeclass
Listing 11.3. Applicative typeclass
Listing 11.4. Configuring an application using the Config class and applicative builder
Listing 11.5. ApplicativeBuilder class