Repository navigation
v0.23.0 Unlimited Arity
This is the biggest update to Molecule yet!
Molecule now leverages Scala 3.7's composable Tuples and polymorphic functions to dramatically simplify and generalize the DSL internals — while keeping the expressive, type-safe API intact.
From Arity-Specific to Tuple-Based DSL
Previously, Molecule generated boilerplate for each arity of each entity:
class Person_0
class Person_1[A]
class Person_2[A, B]
class Person_3[A, B, C]
class Person_4[A, B, C, D]
class Person_5[A, B, C, D, E]
// etc...With the new Tuple-based architecture, we now only generate three core shapes:
class Person_0 // No output attributes
class Person_1[T] // One scalar attribute
class Person_n[Tpl <: Tuple] // Two or more attributes in a tupleThat’s it! Molecules can now contain 100+ attributes with no boilerplate explosion.
Tests with 23 attributes run smoothly and without any hiccups.
Scala 3.7 Required
Molecule now targets the latest Scala version.
To use this release, your project must be built with Scala 3.7.1.
Type-Level Magic – Tuple Manipulation
Scala 3.7 brings powerful tools like Tuple, Init, and : * to manipulate types at compile time.
Consider this molecule:
val cityCountPerCountry: List[(String, Int)] =
Country.name.city(count).query.getHere, apply(count) transforms the city attribute’s output type from String to Int.
Previously, this required updating type parameters (e.g., from B = String to B = Int) and duplicating expression boilerplate across all arities.
Now, we simply use:
Tpl :* String // Add type to the Tuple
Init[Tpl] :* Int // Replace last type in the TupleThis allows expressive, type-safe transformations — with far less generated code.
Internally, we use polymorphic functions like:
[tpl <: Tuple] => (dm: DataModel) => new Country_n[tpl](dm)to thread updated tuple types through Molecule’s expression traits, enabling seamless transformations like apply(count) while retaining precise static types.
Clean Domain Definitions – No More Arity Config
The maxArity parameter on DomainStructure is no longer needed.
You can now define your domain structure simply as:
object Country extends DomainStructure {
// Entity/Attribute definitions...
}And Molecule will generate only the minimal DSL code required — with no risk of "arity explosion".
Compile Time Improvements
Thanks to the dramatically reduced codebase, compilation times have improved by 20–30% in most test projects.
This also means faster iteration cycles during development.
Production size domain definitions with 1000+ Attributes in 80+ entities have been tested to compile and work smoothly.
Summary
- Replaced arity-specific boilerplate with tuple-based DSL generation
- Enabled support for unlimited arity molecules
- Migrated to Scala 3.7.1
- Improved compilation times by 20–30%
- Removed
maxArityconfiguration - Retained full type safety and expressiveness via type-level programming