Handsonscala
Discussion and and code examples for the book Hands-on Scala Programming
Install / Use
/learn @handsonscala/HandsonscalaREADME
Hands-on Scala Programming
This repository is the online hub for the book Hands-on Scala Programming:
-
Chapter Notes, Errata, and Discussion: go here if you want to leave comments or ask questions about individual chapters
-
Code Snippets: copy-paste friendly versions of every code snippet in the book
-
Chapter Resource Files: files used as part of the book's programming exercises
-
Executable Code Examples: self-contained executable programs for the topics being presented in each chapter.
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 Scala CLI scripts 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.mdfile -
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.
Part I Introduction to Scala
Chapter 1: Hands-on Scala
Chapter 2: Setting Up
Chapter 3: Basic Scala
- 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 - SingletonObjects: Basic usage of Singleton Objects
- 3.6 - PrintMessages: A method to render a flat array of
Msginstances 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.
- 3.8 - FlexibleFizzBuzz: Implementation of FizzBuzz that takes a callback used to handle the generated strings
Chapter 4: Scala Collections
- 4.1 - BuildersFactories: Builders and Factory Methods to efficiently construct collections
- 4.2 - Transforms: Various ways of transforming collections
- 4.3 - QueriesAggregations: Querying collections to find elements within, and aggregating data across an entire collection
- 4.4 - Combining: Combining different collection operations together
- 4.5 - ConvertersViews: Converting between collections, and using views to avoid allocating intermediate collections
- 4.6 - ImmutableVectors: Immutable Vectors, convenient ordered indexed collections
- 4.7 - ImmutableSets: Immutable Sets, unordered collections with uniqueness of each item
- 4.8 - ImmutableMaps: Immutable Maps, unordered collections of key-value pairs
- 4.9 - ImmutableLists: Immutable Lists, ordered collections with fast operations at the front
- 4.10 - MutableArrayDeques: Mutable Array Deques, fast mutable ordered indexed collection with adding and removal of elements at both ends
- 4.11 - MutableSets: Mutable Sets, mutable unordered collections with uniqueness of elements
- 4.12 - MutableMaps: Mutable Maps, mutable unordered collections of key-value pairs
- 4.13 - InPlaceOperations: In-place operations for conveniently and efficiently modifying mutable collections
- 4.14 - CommonInterfaces: Using common interfaces to write code that can work across multiple collections
- 4.15 - PartialValidSudoku: Checks whether a partially-filled Sudoku grid is valid so far, with
0s representing empty squares - 4.16 - RenderSudoku: Pretty-prints a Sudoku grid
Chapter 5: Notable Scala Features
- 5.1 - CaseClass: Basic usage of
case classfeatures - 5.2 - SealedTrait: Basic usage of
sealed traits - 5.3 - Enums: Basic usage of
sealed traits - 5.4 - PatternMatching: Demonstration of pattern matching
- 5.5 - ByName: Use cases for by-name method parameters
- 5.6 - ApplyMethod: Examples of Scala
def applymethods - 5.7 - ImplicitParameters: Implicit parameters for dependency injection
- 5.8 - TypeclassInference: Use case for typeclass inference and recursive typeclass inference
- 5.9 - Simplify: Using pattern matching to perform algebraic simplifications on simple equations
- 5.10 - Backoff: A version of our by-name
def retrymethod with configurable exponential backoff - 5.11 - Deserialize: Using recursive typeclass inference to parse and de-serialize arbitrarily-deep data structures from a JSON-like syntax
- 5.12 - Serialize: Using recursive typeclass inference to parse and de-serialize arbitrarily-deep data structures from a JSON-like syntax
Part II Local Development
Chapter 6: Implementing Algorithms in Scala
- 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 anOrdering - 6.3 - Trie: A simple mutable Trie implemention
- [6.4 - Search](https://github.com/handsonscala/handsonsc
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
