Scala course

Scala Level 4: Algebraic Data Types

Algebraic Data Types is level 4 of 13 of the LoWisa Scala course. It has 3 lessons and 9 ideas. Below is every lesson and what it teaches, in one line each.

Updated 2026-11-30

Enums and Case Classes

  • Case classes. A case class is data with dignity: equality, copy and pattern support generated.
  • Scala 3 enums. Scala 3 enums declare sum types cleanly: cases with fields, methods and companions.
  • copy. The copy method changes one field immutably: updates as new values, history intact.

Pattern Matching

  • match. match destructures values across cases: fields bound, guards applied, results returned.
  • Exhaustive matching. Matching a sealed type is exhaustiveness-checked: the missing case is a compile warning you promote to error.
  • Deep patterns. Patterns nest: case Order(_, Address(_, "KE")) reaches inside structures in one line.

Modelling Valid States

  • Make illegal states unrepresentable. ADTs model truth: a Payment is Pending, Settled(ref) or Failed(reason): flag soup deleted.
  • Option over null. Option replaces null: Some(value) or None, handled by match or map, never NPE.
  • Types as documentation. A precise ADT is documentation that fails the build the day it stops being true.

Before and after this level

In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.

Frequently asked questions

What does Scala Level 4: Algebraic Data Types cover?

Enums and Case Classes, Pattern Matching, Modelling Valid States: 3 lessons and 9 ideas.

What should I know before this level?

The level before it, Level 3: Classes & Traits, which covers Classes and Objects, Traits, Composition.

Learn Scala on your phone

The first level is free. LoWisa is on Google Play and the App Store.