See: Programming Scala, 3rd Edition, by Dean Wampler, Publisher : O’Reilly Media; 3rd edition (May 26, 2021)
- https://learning.oreilly.com/library/view/programming-scala-3rd/9781492077886
- https://github.com/deanwampler/programming-scala-book-code-examples
- https://github.com/deanwampler
- Dean Wampler
- https://smile.amazon.com/Programming-Scala-Scalability-Functional-Objects-ebook-dp-B095XLMMGC/dp/B095XLMMGC
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 building today’s highly scalable, data-centric applications while maximizing developer productivity.
While Java remains popular and Kotlin has become popular, Scala hasn’t been sitting still. This third edition covers the new features in Scala 3 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 techniques
- Build killer big data and distributed apps using Scala’s functional combinators and tools like Spark and Akka
- Create concise solutions to challenging design problems with the sophisticated type system, mixin composition with traits, pattern matching, and more
Resources
Errata Page: http://oreilly.com/catalog/0636920365686/errata
Supplemental Content: https://github.com/deanwampler/programming-scala-book-code-examples
About the Author
Dean Wampler is an expert in data engineering for scalable streaming data systems and applications of machine learning and artificial intelligence. He is a principal software engineer at Domino Data Lab. Previously he worked at Anyscale and Lightbend, where he worked on scalable machine learning with Ray and distributed streaming data systems with Apache Spark, Apache Kafka, Kubernetes, and other tools. Besides Programming Scala, Dean is also the author of What Is Ray?, Distributed Computing Made Simple, Fast Data Architectures for Streaming Applications, and Functional Programming for Java Developers, as well as the coauthor of Programming Hive, all from O’Reilly. He is a contributor to several open source projects and a frequent conference speaker, and he co-organizes several conferences around the world and several user groups in Chicago. Dean has a PhD in physics from the University of Washington. Find Dean on Twitter: @deanwampler.
Table of Contents:
By Dean Wampler
- Foreword
- Foreword, Third Edition
- Foreword, First and Second Edition
- Preface
- Welcome to Programming Scala, Third Edition
- How to Read This Book
- Welcome to Programming Scala, Second Edition
- Welcome to Programming Scala, First Edition
- Conventions Used in This Book
- Using Code Examples
- Getting the Code Examples
- O’Reilly Online Learning
- How to Contact Us
- Acknowledgments for the Third Edition
- Acknowledgments for the Second Edition
- Acknowledgments for the First Edition
- 1. Zero To Sixty: Introducing Scalaqueue
- Why Scala?
- The Appeal of Scala
- Why Scala 3?
- Migrating to Scala 3
- Installing the Scala Tools You Need
- Building the Code Examples
- More Tips
- Using sbt
- Running the Scala Command-Line Tools Using sbt
- A Taste of Scala
- A Sample Application
- Recap and What’s Next
- 2. Type Less, Do Morequeue
- New Scala 3 Syntax—Optional Braces
- Semicolons
- Variable Declarations
- Ranges
- Partial Functions
- Method Declarations
- Method Default and Named Parameters
- Methods with Multiple Parameter Lists
- Nesting Method Definitions and Recursion
- Inferring Type Information
- Repeated Parameter Lists
- Language Keywords
- Literal Values
- Numeric Literals
- Boolean Literals
- Character Literals
- String Literals
- Symbol Literals
- Function Literals
- Tuples
- Option, Some, and None: Avoiding Nulls
- When You Really Can’t Avoid Nulls
- Sealed Class Hierarchies and Enumerations
- Organizing Code in Files and Namespaces
- Importing Types and Their Members
- Package Imports and Package Objects
- Parameterized Types Versus Abstract Type Members
- Recap and What’s Next
- 3. Rounding Out The Basics
- Defining Operators
- Allowed Characters in Identifiers
- Methods with Empty Parameter Lists
- Operator Precedence Rules
- Enumerations and Algebraic Data Types
- Interpolated Strings
- Scala Conditional Expressions
- Conditional and Comparison Operators
- for Comprehensions
- for Loops
- Generators
- Guards: Filtering Values
- Yielding New Values
- Expanded Scope and Value Definitions
- Scala while Loops
- Using try, catch, and finally Clauses
- Call by Name, Call by Value
- Lazy Values
- Traits: Interfaces and Mixins in Scala
- When new Is Optional
- Recap and What’s Next
- 4. Pattern Matching
- Safer Pattern Matching with Matchable
- Values, Variables, and Types in Matches
- Matching on Sequences
- Pattern Matching on Repeated Parameters
- Matching on Tuples
- Parameter Untupling
- Guards in Case Clauses
- Matching on Case Classes and Enums
- Matching on Regular Expressions
- Matching on Interpolated Strings
- Sealed Hierarchies and Exhaustive Matches
- Chaining Match Expressions
- Pattern Matching Outside Match Expressions
- Problems in Pattern Bindings
- Pattern Matching as Filtering in for Comprehensions
- Pattern Matching and Erasure
- Extractors
- unapply Method
- Alternatives to Option Return Values
- unapplySeq Method
- Implementing unapplySeq
- Recap and What’s Next
- 5. Abstracting Over Context: Type Classes And Extension Methodsqueue
- Four Changes
- Extension Methods
- Build Your Own String Interpolator
- Type Classes
- Scala 3 Type Classes
- Alias Givens
- Scala 2 Type Classes
- Scala 3 Implicit Conversions
- Type Class Derivation
- Givens and Imports
- Givens Scoping and Pattern Matching
- Resolution Rules for Givens and Extension Methods
- The Expression Problem
- Recap and What’s Next
- 6. Abstracting Over Context: Using Clauses
- Using Clauses
- Context Bounds
- Other Context Parameters
- Context Functions
- Constraining Allowed Instances
- Implicit Evidence
- Working Around Type Erasure with Using Clauses
- Rules for Using Clauses
- Improving Error Messages
- Recap and What’s Next
- 7. Functional Programming In Scalaqueue
- What Is Functional Programming?
- Functions in Mathematics
- Variables That Aren’t
- Functional Programming in Scala
- Anonymous Functions, Lambdas, and Closures
- Purity Inside Versus Outside
- Recursion
- Tail Calls and Tail-Call Optimization
- Partially Applied Functions Versus Partial Functions
- Currying and Uncurrying Functions
- Tupled and Untupled Functions
- Partial Functions Versus Functions Returning Options
- Functional Data Structures
- Sequences
- Maps
- Sets
- Traversing, Mapping, Filtering, Folding, and Reducing
- Traversing
- Mapping
- Flat Mapping
- Filtering
- Folding and Reducing
- Left Versus Right Folding
- Combinators: Software’s Best Component Abstractions
- What About Making Copies?
- Recap and What’s Next
- 8. For Comprehensions In Depthqueue
- Recap: The Elements of for Comprehensions
- for Comprehensions: Under the Hood
- Translation Rules of for Comprehensions
- Options and Container Types
- Option as a Container?
- Either: An Alternative to Option
- Try: When There Is No Do
- Validated from the Cats Library
- Recap and What’s Next
- 9. Object-Oriented Programming In Scalaqueue
- Class and Object Basics: Review
- Open Versus Closed Types
- Classes Open for Extension
- Overriding Methods? The Template Method Pattern
- Reference Versus Value Types
- Opaque Types and Value Classes
- Opaque Type Aliases
- Value Classes
- Supertypes
- Constructors in Scala
- Calling Supertype Constructors
- Export Clauses
- Good Object-Oriented Design: A Digression
- Fields in Types
- The Uniform Access Principle
- Unary Methods
- Recap and What’s Next
- 10. Traitsqueue
- Traits as Mixins
- Stackable Traits
- Union and Intersection Types
- Transparent Traits
- Using Commas Instead of with
- Trait Parameters
- Should That Type Be a Class or Trait?
- Recap and What’s Next
- 11. Variance Behavior And Equalityqueue
- Parameterized Types: Variance Under Inheritance
- Functions Under the Hood
- Variance of Mutable Types
- Improper Variance of Java Arrays
- Equality of Instances
- The equals Method
- The == and != Methods
- The eq and ne Methods
- Array Equality and the sameElements Method
- Equality and Inheritance
- Multiversal Equality
- Case Objects and hashCode
- Recap and What’s Next
- 12. Instance Initialization And Method Resolutionqueue
- Linearization of a Type Hierarchy
- Initializing Abstract Fields
- Overriding Concrete Fields
- Abstract Type Members and Concrete Type Aliases
- Recap and What’s Next
- 13. The Scala Type Hierarchyqueue
- Much Ado About Nothing (and Null)
- The scala Package
- Products, Case Classes, Tuples, and Functions
- Tuples and the Tuple Trait
- The Predef Object
- Implicit Conversions
- Type Definitions
- Condition Checking Methods
- Input and Output Methods
- Miscellaneous Methods
- Recap and What’s Next
- 14. The Scala Collections Libraryqueue
- Different Groups of Collections
- Abstractions with Multiple Implementations
- The scala.collection.immutable Package
- The scala.collection.mutable Package
- The scala.collection Package
- The scala.collection.concurrent Package
- The scala.collection.convert Package
- The scala.collection.generic Package
- Construction of Instances
- The Iterable Abstraction
- Polymorphic Methods
- Equality for Collections
- Nonstrict Collections: Views
- Recap and What’s Next
- 15. Visibility Rulesqueue
- Public Visibility: The Default
- Visibility Keywords
- Protected Visibility
- Private Visibility
- Scoped Private and Protected Visibility
- Recap and What’s Next
- 16. Scala’s Type System, Part Iqueue
- Parameterized Types
- Abstract Type Members and Concrete Type Aliases
- Comparing Abstract Type Members Versus Parameterized Types
- Type Bounds
- Upper Type Bounds
- Lower Type Bounds
- Context Bounds
- View Bounds
- Intersection and Union Types
- Intersection Types
- Union Types
- Phantom Types
- Structural Types
- Refined Types
- Existential Types (Obsolete)
- Recap and What’s Next
- 17. Scala’s Type System, Part IIqueue
- Match Types
- Dependently Typed Methods
- Dependent Method and Dependent Function Types
- Dependent Typing
- Path-Dependent Types
- Using this
- Using super
- Stable Paths
- Self-Type Declarations
- Type Projections
- More on Singleton Types
- Self-Recursive Types: F-Bounded Polymorphism
- Higher-Kinded Types
- Type Lambdas
- Polymorphic Functions
- Type Wildcard Versus Placeholder
- Recap and What’s Next
- 18. Advanced Functional Programmingqueue
- Algebraic Data Types
- Sum Types Versus Product Types
- Properties of Algebraic Data Types
- Final Thoughts on Algebraic Data Types
- Category Theory
- What Is a Category?
- Functor
- The Monad Endofunctor
- The Semigroup and Monoid Categories
- Recap and What’s Next
- 19. Tools For Concurrencyqueue
- The scala.sys.process Package
- Futures
- Robust, Scalable Concurrency with Actors
- Akka: Actors for Scala
- Actors: Final Thoughts
- Stream Processing
- Recap and What’s Next
- 20. Dynamic Invocation In Scalaqueue
- Structural Types Revisited
- A Motivating Example: ActiveRecord in Ruby on Rails
- Dynamic Invocation with the Dynamic Trait
- DSL Considerations
- Recap and What’s Next
- 21. Domain-Specific Languages In Scalaqueue
- Internal DSLs
- External DSLs with Parser Combinators
- About Parser Combinators
- A Payroll External DSL
- Internal Versus External DSLs: Final Thoughts
- Recap and What’s Next
- 22. Scala Tools And Librariesqueue
- Scala 3 Versions
- Command-Line Interface Tools
- Coursier
- Managing Java JDKs with Coursier
- The scalac Command-Line Tool
- The scala Command-Line Tool
- The scaladoc Command-Line Tool
- Other Scala Command-Line Tools
- Build Tools
- Integration with IDEs and Text Editors
- Using Notebook Environments with Scala
- Testing Tools
- Scala for Big Data: Apache Spark
- Typelevel Libraries
- Li Haoyi Libraries
- Java and Scala Interoperability
- Using Java Identifiers in Scala Code
- Scala Identifiers in Java Code
- Java Generics and Scala Parameterized Types
- Conversions Between Scala and Java Collections
- Java Lambdas Versus Scala Functions
- Annotations for JavaBean Properties and Other Purposes
- Recap and What’s Next
- 23. Application Designqueue
- Recap of What We Already Know
- Annotations
- Using @main Entry Points
- Design Patterns
- Creational Patterns
- Structural Patterns
- Behavioral Patterns
- Better Design with Design by Contract
- The Parthenon Architecture
- Recap and What’s Next
- 24. Metaprogramming: Macros And Reflectionqueue
- Scala Compile Time Reflection
- Java Runtime Reflection
- Scala Reflect API
- Type Class Derivation: Implementation Details
- Scala 3 Metaprogramming
- Inline
- Macros
- Staging
- Wrapping Up and Looking Ahead
- A. Significant Indentation Versus Braces Syntaxqueue
- Bibliography