Home / Scala
Scala
Expert Scala 3: opaque, union, intersection and match types, givens in depth, inline and quotes, Futures patterns, actors and channels, and two projects. Every example is verified with the real compiler.
Scala Advanced is the expert level of the Scala track. You already design with generics and bounds, supply values with givens, and run background work with Futures. Across 45 lessons this level takes the type system further: types that hide their underlying representation, unions and intersections of types, types computed by matching, givens with scope and priority rules, code that runs at compile time, and concurrency patterns built on Futures, queues and thread pools. Two closing projects put it together: a JSON parser written by hand and a concurrent pipeline.
Course contents
Work top to bottom — the sidebar is the course. Topics later in the list assume the ones before them.
Scala Advanced
Advanced · ⏱ 4 min · standalone lesson
Advanced Type System
- Opaque Types
- Union Types
- Intersection Types
- Match Types
- Type Members
- Singleton Types
- Type Lambdas
- Phantom Types
Givens in Depth
Start: Given Imports ❯Metaprogramming at a First Look
Start: Inline Basics ❯Concurrency in Depth
- Future Composition Patterns
- Future Traversal
- Future Timeouts
- Blocking
- Actors at a First Look
- Thread Pools
- Parallel Patterns
- Channels at a First Look
Functional Patterns in Depth
- Error Accumulation
- For-Comprehension Desugaring
- Recursion Schemes
- Fold Patterns
- Memoization
- Composition Patterns
- Trampolines
- Effect Patterns
- State Patterns
Performance and Benchmarking
- Benchmarking Notes
- Algorithmic Choices
- Collection Choices
- Lazy vs Eager Cost
- String Building
- A Benchmark Harness
Project: JSON Parser
Advanced · ⏱ 8 min · standalone lesson
Project: Concurrent Pipeline
Advanced · ⏱ 8 min · standalone lesson
Learn Scala Advanced
At the beginner and intermediate levels, the compiler checked your work. At the advanced level, the compiler becomes a design partner. An opaque type lets you hide that a user id is really a number, so no other part of the program can mix it up with a plain count. A union type says a value is one of two kinds, and an intersection type says it satisfies two descriptions at once. A match type goes one step further: it is a small computation that runs on types themselves, picking a result type from the shape of its input. These tools let whole classes of mistakes become compile errors instead of wrong answers.
Givens grow up in this level too. You learn where the compiler searches for them, how to import them from another object, how a specific instance beats a general fallback, and how the compiler can derive an instance for a case class on its own. Context functions round the picture out: functions that draw a value from their surroundings instead of taking it as an argument. Metaprogramming gets a careful first look: inline methods the compiler pastes at the call site, operations that run during compilation, and quotes and splices, with the honest rule that a macro must be compiled before it can be called.
The rest of the level is about programs that do more than one thing at once and programs that must be fast. Futures are composed into pipelines, traversed in batches, given timeouts with fixed fallbacks, and joined by hand-built actors and channels that drain to one final answer. Functional patterns give you error accumulation across a whole batch, the desugared form of a for-comprehension, folds over your own tree shapes, stack-safe recursion through trampolines, and tiny effect and state wrappers built from scratch. Performance is taught with counts rather than a stopwatch on the page, so every claim stays checkable. The JSON parser and the concurrent pipeline at the close draw on everything before them.
What you will learn
When you finish, you will be able to:
- Hide a representation behind an opaque type, and expose only the operations its own object allows.
- Combine types with unions and intersections, and compute a result type with a match type.
- Declare abstract type members in a trait, and use literal singleton types and phantom tags to carry facts at compile time.
- Import givens, reason about their scopes, settle clashes with priority rules, and derive instances for case classes.
- Write context functions that summon what they need, and extension methods that work for any element type.
- Use inline methods, transparent inline results, inline matches and compile-time operations, and explain what quotes and splices can and cannot do in one file.
- Compose, traverse and time out Futures, mark blocking work, and build actors, channels and thread pools from queues and the JDK.
- Accumulate every validation error in a batch, desugar a for-comprehension by hand, and fold over a custom tree shape.
- Write stack-safe recursion with trampolines, and model deferred effects and threaded state with small wrapper classes.
- Judge speed with counts instead of wall time, choose between strict and lazy collection work, and finish by building a JSON parser and a concurrent pipeline.
Who this Scala Advanced course is for
You should arrive with the Intermediate toolkit already in hand: generic methods under bounds, givens and using clauses, type classes, extractors, sealed hierarchies, views, Option, Either and Try in depth, and Futures with execution contexts and promises. If any of that feels new, take Scala Intermediate first and return here afterwards. This level builds on those ideas without repeating them.
Library authors are the natural audience: people who want their own types to carry guarantees, their own instances to be derived, and their own pipelines to stay correct under concurrency. Backend and data engineers get the same payoff in a different shape: a pipeline that cannot silently pass a wrong type is worth more than one that merely runs fast.
This is not a framework survey. No Akka, Cats or ZIO appears anywhere; the standard library and the JDK carry every lesson, which keeps each idea portable to the next library you adopt.
How this course works
The course has 45 lessons, and their estimates add up to 198 minutes, a little over three hours spent reading and experimenting. Go in order: later categories build on earlier ones, so the concurrency lessons lean on for-comprehensions and error handling, and the concurrent pipeline leans on the functional patterns and the thread pool lessons.
Lessons stay short. A plain definition comes first, then small programs that each prove a single idea, then a fuller program that combines them. Every lesson ends with a question whose solution explains the reasoning, so even a wrong guess leaves you with something learned.
Every snippet and closing program was compiled with Scala 3.3.4 and executed two times, and the page shows exactly what those runs printed. Futures are awaited before anything prints, so the page never depends on which background job happened to finish first. Timing never appears in a printed result, since a measured time changes between runs; performance claims are shown as counts instead.
Because Scala compiles before it runs, the Try-it box displays the checked result rather than executing anything on the page. When you want to try something yourself, each lesson links to Scastie, where real Scala runs in the browser. The site remembers which lessons you finished, in your own browser, as you go.
Frequently asked questions
Do I need Scala Intermediate first?
Yes. The course assumes generic methods under bounds, givens and using clauses, type classes, extractors, sealed hierarchies, views, Option, Either and Try in depth, and Futures. Anyone missing that background should start with Scala Intermediate, or with Scala Beginner before it.
What Scala version does this course use?
Scala 3.3.4, written in the indentation style Scala 3 prefers. Where a Scala 2 habit would mislead, the lesson says so; otherwise the course simply teaches Scala 3.
Do I need to install anything?
No installation is needed. Lessons are read in the browser, and each one links to Scastie for running real Scala.
Are Akka, Cats or ZIO covered here?
No. The whole level stays inside the Scala standard library plus the JDK. Actors here are a queue plus a thread you write yourself, and effects are a small wrapper class, so the ideas arrive before any framework's vocabulary.
What is a match type?
A match type is a type alias that matches on its type argument and picks a result type, the way a match expression picks a value. One example from the course maps a String argument to Char and an array argument to its element type, so the result type is computed rather than written out.
What can I build after this course?
Libraries with strong compile-time guarantees, concurrent pipelines that drain to one final answer, hand-written parsers, and validation that reports every error in a batch. The two closing projects, a JSON parser and a concurrent pipeline, are working examples of that shape in action.
Next steps
- Scala Intermediate ❯ — The level before this one: generics and bounds, givens and type classes, extractors, Futures and resource safety.
- Kotlin Advanced ❯ — Another advanced-level course, for readers who want a second expert course after Scala.