liveBook · Manning

Sealed trait

A sealed trait is a Scala trait whose permitted subtypes are restricted to declarations known to the compiler.

How 2 Manning books explain it

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

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.