Master Scala Rest APIs in 3 Simple Concepts: Illustrated Guide with Tapir, http4s, and Circe! (3/3)
Full access on: LovinData — Simplified Full Stack Data Engineering
5 min readMar 6, 2024
All parts:
- Master Scala Rest APIs in 3 Simple Concepts: Illustrated Guide with Tapir, http4s, and Circe! (1/3)
- Master Scala Rest APIs in 3 Simple Concepts: Illustrated Guide with Tapir, http4s, and Circe! (2/3)
- 👉 Master Scala Rest APIs in 3 Simple Concepts: Illustrated Guide with Tapir, http4s, and Circe! (3/3)
🧙♂️ Crack ADTs!
Theory
Algebraic Data Types (ADTs) are a way of defining data structures by combining simpler types through two main constructs: Sum Types, representing a choice between alternatives, and Product Types, representing a combination of different types.
Blablabla 🤪, remember that it’s commonly just a sealed trait, like this for example (refer to comments if you want to understand in detail):
sealed trait Pet // It's an ADT because "Product types" and "Sum types"
object Pet {
case class Dog(name: String,
age: Int) // 👈 "Product types" because "(String, Int)" == More complex type by combining types
extends Pet // "Sum types" because "Dog != Cat != Fish != Bird but Dog + Cat + Fish + Bird = Pet" == Distinct types when united define the type
case class Cat(name: String…