/handsonscala

Discussion and and code examples for the book Hands-on Scala Programming

Primary LanguageTSQLOtherNOASSERTION

Hands-on Scala Programming

This repository is the online hub for the book Hands-on Scala Programming:

Executable Code Examples

The executable code examples from Hands-on Scala are freely available online, and open source under an MIT license. These examples are meant to be useful to anyone who is interested in learning Scala, whether or not they are working through Hands-on Scala Programming, though following along with the book will give you the best experience and help you get the most out of them.

Each example is:

  • Self-contained: to be run either using the Ammonite script runner or Mill build tool, with no other setup

  • Tested: with simple test suites provided and instructions on how to run each example in that folder's readme.md file

  • Executable: you can download the folder and run the example yourself to see it in action

Many of the examples are related, with only small code changes between them to illustrate a new feature or technique. The readme.md file of such downstream examples will show a diff from the upstream example that it was based upon, so you can focus your attention on the important code changes that are happening, with a link back up to the upstream example.

The executable code examples below are organized by each part and each chapter of the book.

  • 3.1 - Values: Using Numbers, Strings, Options and Arrays
  • 3.2 - LoopsConditionals: Using Loops, If-Else statements and expressions, and List Comprehensions
  • 3.3 - MethodsFunctions: Basic Usage of Methods and Function Values
  • 3.4 - ClassesTraits: Basic usage of Classes and Traits
  • 3.5 - FlexibleFizzBuzz: Implementation of FizzBuzz that takes a callback used to handle the generated strings
  • 3.6 - PrintMessages: A method to render a flat array of Msg instances into a "threaded" conversation with child messages printed nested under their parents
  • 3.7 - ContextManagers: Methods that act as Python "context managers", opening a file reader/writer, passing the reader/writer to a callback, and closing the file after.
  • 6.1 - MergeSort: Simple merge-sort implemention, hard-coded to only work on Array[Int]
  • 6.2 - GenericMergeSort: Generic merge sort implemention, that can sort any IndexedSeq[T] with an Ordering
  • 6.3 - Trie: A simple mutable Trie implemention
  • 6.4 - Search: Breadth-first-search implemention
  • 6.5 - SearchPaths: Breadth-first-search implemention that keeps track of the shortest paths to every node
  • 6.6 - BinarySearch: Binary search implementation
  • 6.7 - ImmutableTrie: Immutable trie implementation
  • 6.8 - DepthSearchPaths: Depth-first search implementation that keeps track of shortest paths
  • 6.9 - Sudoku: Sudoku solver implemented via depth-first search
  • 6.10 - TrieMap: Using a trie to implement a Map[String, T]-like data structure
  • 6.11 - FloodFill: Breadth-first implemention of a floodfill algorithm, taking a callback that allows the user to specify what color pairs are similar enough to traverse
  • 9.1 - Printing: Listing blog-post-like files in a folder and printing them out
  • 9.2 - Index: Rendering an index.html for our static blog using Scalatags
  • 9.3 - Markdown: Rendering individual blog posts using Atlassian's Commonmark-Java library
  • 9.4 - Links: Adding links between our index.html and the individual blog posts
  • 9.5 - Bootstrap: Prettifying our static blog using the Bootstrap CSS framework
  • 9.6 - Deploy: Optionally deploying our static blog to a Git repository
  • 9.7 - DeployTimestamp: Displaying the .md file last-modified time on each blog post
  • 10.1 - Simple: Simple linear build pipeline
  • 10.2 - Nonlinear: Simple non-linear build pipeline with two branches
  • 10.3 - Modules: Simple non-linear build pipeline, replicated in several modules
  • 10.4 - NestedModules: Nested modules in a Mill build pipeline
  • 10.5 - CrossModules: Using cross-modules to dynamically construct a build graph based on the filesystem
  • 10.6 - Blog: Our static blog generator, converted into an incremental Mill build pipeline
  • 10.7 - ExtendedBlog: Adding previews and bundled Bootstrap CSS to our static blog build pipeline
  • 10.8 - Push: Re-adding the ability to deploy our static blog by defining a T.command
  • 10.9 - PostPdf: Static blog pipeline which can generate PDFs for each blog post using Puppeteer
  • 10.10 - ConcatPdf: Static blog pipeline which can generate PDFs for each blog post and concatenate them using Apache PDFBox
  • 11.1 - ScrapingWiki: Scraping headlines off the Wikipedia front page using Jsoup
  • 11.2 - ScrapingDocs: Scraping semi-structured content off of the Mozilla Development Network Web API docs
  • 11.3 - ApiStatus: Using Jsoup to scrape the status annotations for every Web API on MDN
  • 11.4 - ExternalLinks: Crawling the pages of a static website to extract every external link on the site
  • 11.5 - ScrapingTrees: Using Jsoup to scrape the tree-shaped comments of a threaded discussion forum
  • 17.1 - Main: Simple two-process batch file synchronizer that could work over a network
  • 17.2 - FileSyncer: Simple two-process batch file synchronizer that could work over a network
  • 17.3 - Pipelined: Pipelined version of our two-process file synchronizer, minimizing the chattiness of the protocol
  • 17.4 - Deletes: Pipelined two-process file synchronizer that supports deletions
  • 17.5 - Gzip: File syncer with compressed data exchange between the Sync and Agent processes
  • 17.6 - Ssh: Networked of our two-process file synchronizer, running the agent on a separate computer and interacting with it over SSH
  • 18.1 - Simple: Simple real-time file synchronizer that uses os.watch to react to filesystem changes as they happen
  • 18.2 - Pipelined: Pipelined real-time file synchronizer, allowing RPCs and hashing to take place in parallel
  • 18.3 - InitialFiles: Real-time file synchronizer that supports syncing an initial set of files
  • 18.4 - ForkJoinHashing: Real-time file synchronizer that does hashing of files in parallel
  • 18.5 - Deletes: Real-time file synchronizer supporting deletion of files
  • 18.6 - VirtualFileSystem: Real-time file synchronizer that keeps track of synced files, avoiding RPCs for destination file hashes