liveBook · Manning

Sealed trait

As explained in Akka in Action, Second Edition

A sealed trait is a Scala trait whose permitted direct subtype cases are restricted so the compiler can check pattern-match exhaustiveness.

A sealed trait defines the top of a restricted message hierarchy. In Scala, the compiler can warn when pattern matching does not handle every permitted case. section 2.3

A wallet command protocol

A typed actor can accept a Command protocol instead of raw integers: sealed trait Command, with Increase(amount: Int) and Decrease(amount: Int) extending it. The actor pattern-matches these commands to update wallet state or stop when a limit is exceeded. section 2.3

How Akka in Action, Second Edition covers it

How deep it goes
Defines sealed traits and exhaustiveness warnings, then applies them in a wallet actor without detailing compiler internals.
Examples
Uses a wallet with Increase and Decrease commands, bounded state, and stopping after an excessive increase.
What it assumes
Assumes basic Scala traits and pattern matching while introducing sealed hierarchies through an actor wallet example.
What you can do after
Build typed actor protocols whose pattern matches receive compiler warnings for omitted command cases.
How it connects
Connects traits, pattern matching, actor protocols, behaviors, and typed actors.

Also explained in

Compare how 2 books explain sealed trait →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.