Programming Scala, 3rd Edition

Book description

Get up to speed on Scala—the JVM, JavaScript, and natively compiled language that offers all the benefits of functional programming, a modern object model, and an advanced type system. Packed with code examples, this comprehensive book shows you how to be productive with the language and ecosystem right away. You’ll learn why Scala is ideal for today’s highly scalable, data-centric applications that support concurrency and distribution.

Despite the reinvigoration of Java and the introduction of Kotlin, Scala hasn’t been sitting still. This third edition covers the new features in Scala 3.0, with updates throughout the book. Programming Scala is ideal for beginning to advanced developers who want a complete understanding of Scala’s design philosophy and features with a thoroughly practical focus.

  • Program faster with Scala’s succinct and flexible syntax
  • Dive into basic and advanced functional programming (FP) techniques
  • Build killer big data and distributed apps, using Scala’s functional combinators and tools including Akka and Spark
  • Use traits for mixin composition and pattern matching for data extraction
  • Learn the sophisticated type system that combines functional programming and object-oriented programming concepts

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Welcome to Programming Scala, Third Edition
    2. Welcome to Programming Scala, Second Edition
    3. Welcome to Programming Scala, First Edition
    4. Conventions Used in This Book
    5. Using Code Examples
      1. Getting the Code Examples
    6. O’Reilly Safari
    7. How to Contact Us
    8. Acknowledgments for the Third Edition
    9. Acknowledgments for the Second Edition
    10. Acknowledgments for the First Edition
  2. 1. Zero to Sixty: Introducing Scala
    1. Why Scala?
      1. The Seductions of Scala
    2. Why Scala 3?
      1. Migrating to Scala 3
    3. Installing Scala
      1. Coursier
      2. Java JDK
      3. SBT
      4. Scala
    4. Building the Code Examples
    5. More Tips
      1. Using SBT
      2. Running the Scala Command-Line Tools
    6. A Taste of Scala
    7. A Sample Application
    8. Recap and What’s Next
  3. 2. Type Less, Do More
    1. New Scala 3 Syntax
    2. Semicolons
    3. Variable Declarations
    4. Ranges
    5. Partial Functions
    6. Infix Operator Notation
    7. Method Declarations
      1. Method Default and Named Parameters
      2. Methods with Multiple Parameter Lists
      3. Nesting Method Definitions and Recursion
    8. Inferring Type Information
    9. Variadic Argument Lists
    10. Reserved Words
    11. Literal Values
      1. Numeric Literals
      2. Boolean Literals
      3. Character Literals
      4. String Literals
      5. Symbol Literals
      6. Function Literals
      7. Tuple Literals
    12. Option, Some, and None: Avoiding nulls
      1. When You Can’t Avoid Nulls
    13. Sealed Class Hierarchies and Enumerations
    14. Organizing Code in Files and Namespaces
    15. Importing Types and Their Members
      1. Package Imports and Package Objects
    16. Abstract Types Versus Parameterized Types
    17. Recap and What’s Next
  4. 3. Rounding Out the Basics
    1. Operator Overloading?
    2. Allowed Characters in Identifiers
      1. Syntactic Sugar
    3. Methods with Empty Parameter Lists
    4. Precedence Rules
      1. Left vs. Right Associative Methods
    5. Enumerations and Algebraic Data Types
    6. Interpolated Strings
    7. Scala if Expressions
    8. Conditional Operators
    9. Scala for Comprehensions
      1. for Loops
      2. Generator Expressions
      3. Guards: Filtering Values
      4. Yielding New Values
      5. Expanded Scope and Value Definitions
    10. Scala while Loops
      1. Scala do-while Loops
    11. Using try, catch, and finally Clauses
    12. Call by Name, Call by Value
    13. lazy val
    14. Traits: Interfaces and “Mixins” in Scala
    15. Recap and What’s Next
  5. 4. Pattern Matching
    1. Values, Variables, and Types in Matches
    2. Matching on Sequences
    3. Matching on Tuples
      1. Parameter Untupling
    4. Guards in case Clauses
    5. Matching on Case Classes and Enums
    6. Matching on Regular Expressions
    7. More on Type Matching
    8. Sealed Hierarchies and Exhaustive Matches
    9. Chaining Match Expressions
    10. Pattern Matching in Other Contexts
      1. Problems in Pattern Bindings
    11. Extractors
      1. unapply Method
      2. Alternatives to Option Return Values
      3. unapplySeq Method
      4. Implementing unapplySeq
    12. Concluding Remarks on Pattern Matching
    13. Recap and What’s Next
  6. 5. Abstracting over Context, Part I
    1. Four Changes
    2. Extension Methods
    3. Type Classes
      1. Scala 3 Type Classes
      2. Scala 2 Type Classes
    4. Implicit Conversions
      1. Rules for Implicit Conversion Resolution
    5. Type Class Derivation
      1. Givens and Imports
    6. Resolution Rules for Givens and Extension Methods
      1. Build Your Own String Interpolator
      2. The Expression Problem
    7. Wise Use of Type Extensions
    8. Recap and What’s Next
  7. 6. Abstracting over Context, Part II
    1. Using Clauses
    2. Context Bounds
      1. By-Name Context Parameters
    3. Other Context Parameters
    4. Passing Context Functions
    5. Constraining Allowed Instances
    6. Implicit Evidence
    7. Working Around Type Erasure with Context Bounds
    8. Rules for Using Clauses
    9. Improving Error Messages
    10. Recap and What’s Next
  8. Index

Product information

  • Title: Programming Scala, 3rd Edition
  • Author(s): Dean Wampler
  • Release date: August 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492077879