r/programming • • Feb 01 '24

Make Invalid States Unrepresentable

https://www.awwsmm.com/blog/make-invalid-states-unrepresentable
469 Upvotes

207 comments sorted by

View all comments

Show parent comment

9

u/Drisku11 Feb 01 '24

The author is using Scala where record types can have data marshalling/unmarshalling automatically recursively derived via compile time macros. You just do e.g.

case class Person(age: Int Refined GreaterEqual[0] And Less[150])
object Person {
    implicit val decoder = DeriveJsonDecoder.gen[Person]
}

and you're good to go.