0%

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

Table of Contents

  1. Foreword
  2. 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
  3. 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
  4. 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
  5. 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 Conditional 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
  6. 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
  7. 5. Abstracting over Context: Type Classes and Extension Methods
    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
  8. 6. Abstracting over Context: Using Clauses
    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
  9. 7. Functional Programming in Scala
    1. What Is Functional Programming?
      1. Functions in Mathematics
      2. Variables That Aren’t
    2. Functional Programming in Scala
      1. Anonymous Functions, Lambdas, and Closures
      2. Purity Inside Versus Outside
    3. Recursion
    4. Tail Calls and Tail-Call Optimization
      1. Trampoline for Tail Calls
    5. Partially Applied Functions Versus Partial Functions
    6. Currying and Uncurrying Functions
    7. Tupled and Untupled Functions
    8. Partial Functions vs. Functions Returning Options
    9. Functional Data Structures
      1. Sequences
      2. Maps
      3. Sets
    10. Traversing, Mapping, Filtering, Folding, and Reducing
      1. Traversal
      2. Mapping
      3. Flat Mapping
      4. Filtering
      5. Folding and Reducing
      6. Left Versus Right Folding
    11. Combinators: Software’s Best Component Abstractions
    12. What About Making Copies?
    13. Recap and What’s Next
  10. 8. for Comprehensions in Depth
    1. Recap: The Elements of for Comprehensions
    2. For Comprehensions: Under the Hood
    3. Translation Rules of for Comprehensions
    4. Options and Other Container Types
      1. Option as a Container
      2. Either: A Logical Extension to Option
      3. Try: When There Is No Do
      4. Cats Validator
    5. Recap and What’s Next
  11. 9. Object-Oriented Programming in Scala
    1. Class and Object Basics: Review
      1. When new Is Optional
    2. Open vs. Closed Types
      1. Classes Open for Extension
      2. Overriding Methods? The Template Method Pattern
      3. Using @main Entry Points
    3. Reference Versus Value Types
    4. Opaque Types and Value Classes
      1. Opaque Types
      2. Value Classes
    5. Parent Types
    6. Constructors in Scala
    7. Calling Parent Class Constructors
    8. Export Clauses
    9. Good Object-Oriented Design: A Digression
    10. Methods in Types
    11. Fields in Types
      1. The Uniform Access Principle
      2. Unary Methods
    12. Validating Input
    13. Nested Types
    14. Case Objects and hashCode
    15. Recap and What’s Next
  12. 10. Traits
    1. Traits as Mixins
    2. Stackable Traits
    3. Union and Intersection Types
    4. Super Traits
    5. Using Commas Instead of With
    6. Trait Parameters
    7. Should That Type Be a Class or Trait?
    8. Recap and What’s Next
52.14.126.74