Foreword | 9 |
I Introduction to Scala | 13 |
| 1 Hands-on Scala | 15 |
| 2 Setting Up | 25 |
| 3 Basic Scala | 39 |
| 4 Scala Collections | 63 |
| 5 Notable Scala Features | 83 |
II Local Development | 109 |
| 6 Implementing Algorithms in Scala | 111 |
| 7 Files and Subprocesses | 131 |
| 8 JSON and Binary Data Serialization | 151 |
| 9 Self-Contained Scala Scripts | 167 |
| 10 Static Build Pipelines | 183 |
III Web Services | 205 |
| 11 Scraping Websites | 207 |
| 12 Working with HTTP APIs | 223 |
| 13 Fork-Join Parallelism with Futures | 241 |
| 14 Simple Web and API Servers | 263 |
| 15 Querying SQL Databases | 287 |
IV Program Design | 309 |
| 16 Message-based Parallelism with Actors | 311 |
| 17 Multi-Process Applications | 331 |
| 18 Building a Real-time File Synchronizer | 347 |
| 19 Parsing Structured Text | 363 |
| 20 Implementing a Programming Language | 385 |
Conclusion | 409 |
| 1 Hands-on Scala | 15 |
| 1.1 Why Scala and Why This Book? | 16 |
| 1.2 How This Book Is Organized | 17 |
| 1.3 Code Snippet and Examples | 19 |
| 1.4 Online Materials | 21 |
| 2 Setting Up | 25 |
| 2.1 Installing Mill | 26 |
| 2.2 IDE Support | 34 |
| 3 Basic Scala | 39 |
| 3.1 Values | 40 |
| 3.2 Loops, Conditionals, Comprehensions | 47 |
| 3.3 Methods and Functions | 50 |
| 3.4 Classes | 54 |
| 3.5 Traits | 56 |
| 3.6 Singleton Objects | 57 |
| 3.7 Optional Braces and Indentation | 59 |
| 4 Scala Collections | 63 |
| 4.1 Operations | 64 |
| 4.2 Immutable Collections | 69 |
| 4.3 Mutable Collections | 75 |
| 4.4 Common Interfaces | 79 |
| 5 Notable Scala Features | 83 |
| 5.1 Case Classes, Sealed Traits, and Enums | 84 |
| 5.2 Pattern Matching | 88 |
| 5.3 By-Name Parameters | 94 |
| 5.4 Apply Methods | 96 |
| 5.5 Implicit Parameters | 97 |
| 5.6 Typeclass Inference | 99 |
| 6 Implementing Algorithms in Scala | 111 |
| 6.1 Merge Sort | 112 |
| 6.2 Prefix Tries | 115 |
| 6.3 Breadth First Search | 123 |
| 6.4 Shortest Paths | 125 |
| 7 Files and Subprocesses | 131 |
| 7.1 Paths | 132 |
| 7.2 Filesystem Operations | 134 |
| 7.3 Folder Syncing | 138 |
| 7.4 Simple Subprocess Invocations | 142 |
| 7.5 Interactive and Streaming Subprocesses | 146 |
| 8 JSON and Binary Data Serialization | 151 |
| 8.1 Manipulating JSON | 152 |
| 8.2 JSON Serialization of Scala Data Types | 155 |
| 8.3 Writing your own Generic Serialization Methods | 159 |
| 8.4 Binary Serialization | 162 |
| 9 Self-Contained Scala Scripts | 167 |
| 9.1 Reading Files Off Disk | 168 |
| 9.2 Rendering HTML with Scalatags | 169 |
| 9.3 Rendering Markdown with Commonmark-Java | 171 |
| 9.4 Links and Bootstrap | 175 |
| 9.5 Optionally Deploying the Static Site | 179 |
| 10 Static Build Pipelines | 183 |
| 10.1 Mill Build Pipelines | 184 |
| 10.2 Mill Modules | 188 |
| 10.3 Revisiting our Static Site Script | 192 |
| 10.4 Conversion to a Mill Build Pipeline | 192 |
| 10.5 Extending our Static Site Pipeline | 196 |
| 11 Scraping Websites | 207 |
| 11.1 Scraping Wikipedia | 208 |
| 11.2 MDN Web Documentation | 212 |
| 11.3 Scraping MDN | 214 |
| 11.4 Putting it Together | 218 |
| 12 Working with HTTP APIs | 223 |
| 12.1 The Task: Github Issue Migrator | 224 |
| 12.2 Creating Issues and Comments | 226 |
| 12.3 Fetching Issues and Comments | 228 |
| 12.4 Migrating Issues and Comments | 233 |
| 13 Fork-Join Parallelism with Futures | 241 |
| 13.1 Parallel Computation using Futures | 242 |
| 13.2 N-Ways Parallelism | 245 |
| 13.3 Parallel Web Crawling | 248 |
| 13.4 Asynchronous Futures | 253 |
| 13.5 Asynchronous Web Crawling | 257 |
| 14 Simple Web and API Servers | 263 |
| 14.1 A Minimal Webserver | 264 |
| 14.2 Serving HTML | 267 |
| 14.3 Forms and Dynamic Data | 269 |
| 14.4 Dynamic Page Updates via API Requests | 277 |
| 14.5 Real-time Updates with Websockets | 281 |
| 15 Querying SQL Databases | 287 |
| 15.1 Setting up ScalaSql and PostgreSQL | 288 |
| 15.2 Mapping Tables to Case Classes | 290 |
| 15.3 Querying and Updating Data | 294 |
| 15.4 Transactions | 300 |
| 15.5 A Database-Backed Chat Website | 301 |
| 16 Message-based Parallelism with Actors | 311 |
| 16.1 Castor Actors | 312 |
| 16.2 Actor-based Background Uploads | 314 |
| 16.3 Concurrent Logging Pipelines | 320 |
| 16.4 Debugging Actors | 326 |
| 17 Multi-Process Applications | 331 |
| 17.1 Two-Process Build Setup | 332 |
| 17.2 Remote Procedure Calls | 334 |
| 17.3 The Agent Process | 336 |
| 17.4 The Sync Process | 338 |
| 17.5 Pipelined Syncing | 340 |
| 18 Building a Real-time File Synchronizer | 347 |
| 18.1 Watching for Changes | 348 |
| 18.2 Real-time Syncing with Actors | 349 |
| 18.3 Testing the Syncer | 355 |
| 18.4 Pipelined Real-time Syncing | 357 |
| 18.5 Testing the Pipelined Syncer | 359 |
| 19 Parsing Structured Text | 363 |
| 19.1 Simple Parsers | 364 |
| 19.2 Parsing Structured Values | 369 |
| 19.3 Implementing a Calculator | 374 |
| 19.4 Parser Debugging and Error Reporting | 379 |
| 20 Implementing a Programming Language | 385 |
| 20.1 Interpreting Jsonnet | 386 |
| 20.2 Jsonnet Language Features | 386 |
| 20.3 Parsing Jsonnet | 388 |
| 20.4 Evaluating the Syntax Tree | 398 |
| 20.5 Serializing to JSON | 403 |