Sealed trait
A sealed trait is a Scala trait whose permitted subtypes are restricted to declarations known to the compiler.
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.
- How it is used
- Structures typed actor protocols so messages form an explicit, compiler-checkable hierarchy.
- 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 you can do after
- Build typed actor protocols whose pattern matches receive compiler warnings for omitted command cases.
Read how Akka in Action, Second Edition explains sealed trait →
Functional Programming in Scala, Second Edition
A sealed trait hierarchy is a Scala type hierarchy whose permitted subtypes are restricted to declarations known to the compiler.
- How it is used
- Defines closed algebraic data types whose constructors support reliable recursive operations and exhaustive pattern matching.
- How deep it goes
- Explains traits, same-file constructors, companion objects and list implementation, but defers minor trait differences and broader abstraction details.
- Examples
- Uses List with Cons and Nil, plus recursive size operations, to demonstrate a closed constructor set.
- What you can do after
- Build sealed Scala data types with case-based operations and compiler-checkable exhaustive matches.
Read how Functional Programming in Scala, Second Edition explains sealed trait →
Related concepts
- enumalternative to · An enum is a type or language construct whose values are selected from a finite set of named alternatives, which may carry associated data.
- algebraic data typeused by · An algebraic data type is a composite type whose values are formed from product structures, finite alternatives, or both through type constructors.
- actor protocolpart of · An actor protocol is the set of message types and communication rules that defines how an actor can be addressed.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

