# Scala Level 4: Algebraic Data Types

> Level 4: Algebraic Data Types of the LoWisa Scala course: Enums and Case Classes, Pattern Matching, Modelling Valid States. 3 lessons and 9 ideas, each explained in one line.

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

## 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

- **Before:** [Level 3: Classes & Traits](/courses/scala/level-3-classes-and-traits/): Classes and Objects, Traits, Composition.
- **Next:** [Level 5: Functional Programming](/courses/scala/level-5-functional-programming/): Higher-Order Functions, Pure Functions and Immutability, Function Composition.

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](/help/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.

---

Source: https://lowisa.dev/courses/scala/level-4-algebraic-data-types/ · Updated 2026-11-30
