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

James JIANG
5 min readMar 6, 2024

--

All parts:

🧙‍♂️ 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…

--

--

James JIANG
James JIANG

Written by James JIANG

Dedicated 👨🏻‍💻 Full-Stack Data Engineer | Lead Data Engineer @ Datategy (🇫🇷) | 🎓 ENSEEIHT Alumni in Computer Science | Committed to data-driven solutions.

No responses yet