List of Listings

Chapter 1. Scala—a blended language

Listing 1.1. Byte conversions in scala.Predef object

Listing 1.2. Simple Java object

Listing 1.3. Implementing a first-class function in Java

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.20. Merging options

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

Listing 2.25. Using scala.Equals

Listing 2.26. Using new equals and canEquals methods

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

Listing 3.17. Multiple inheritance with mixed override

Listing 3.18. Using the @switch annotation

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.3. Wildcard imports

Listing 5.4. Explicit imports

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

Listing 5.10. Scoped precedence

Listing 5.11. ComplexNumber class

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

Listing 6.16. Appropriately working with variance

Listing 6.17. Ensuring the correct type changes

Chapter 7. Using implicits and types together

Listing 7.1. The <:< type

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

Listing 7.10. Basic HList implementation

Listing 7.11. IndexedView

Listing 7.12. Natural numbers encoded into types

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

Listing 9.6. BranchNode

Listing 9.7. AdaptiveSearchNode

Listing 9.8. Creating an adaptive scatter-gather tree

Chapter 10. Integrating Scala with Java

Listing 10.1. The add2 method

Listing 10.2. Parcelable Address for Android

Chapter 11. Patterns in functional programming

Listing 11.1. Functor typeclass

Listing 11.2. Monad typeclass

Listing 11.3. Applicative typeclass

Listing 11.4. Configuring an application using the Config class and applicative builder

Listing 11.5. ApplicativeBuilder class

Listing 11.6. Automated resource management interface

Listing 11.7. ManagedResource functor and monad instances

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.172.115