Arseniy Zhizhelev - Relational Algebra in Scala3 - how is it possible?

Опубликовано: 04 Декабрь 2024
на канале: Konfy
569
19

Case classes for data representation are often not very convenient. For instance, if the data is not yet complete, we even cannot create an instance of a case class. When we read data from some external source, there might be conversion errors instead of values and sometimes we wish to deal with partial data even when some fields are not filled.

If we create different case classes for various needs in our system, it becomes tedious and error-prone to convert case classes that correspond to the same entity. What we could do instead is to use typed ontology to describe the entity schema and then use some generic representation of data that is based on the same schema. A generic representation might be `Map[String, Any]`, a tuple with appropriate values, a tuple of `Option`s, tuple of `Either`s, ... Due to the fact that these generic representations are based on the same schema, conversion becomes error-free and straight-forward.

So, we can construct new record types ad-hoc, without the need to create dedicated case classes. This opens the path to implement Cartesian products, projections, and other operations of relational algebra.

This experiment has become possible in Scala3 due to the advances in the type systems.

https://2022.scala.love
  / scala_love