Macros and Reflective Calls to eliminate boilerplate
In our previous post, we told you about updatable, a library that empowers programmers to build and update immutable objects in generic contexts. We saw the builder macro as a main element in the library, but we did not explain in detail how it was implemented. We think it uses an interesting pattern to eliminate boilerplate, so we want to share it with you. Instead of showing the original updatable builder, we are going to use a reduced version, in order to keep the example small. We call it factory, because its unique aim is to instantiate traits. Now let’s get to work!
Even in Scala, there are situations where we can find annoying boilerplate. That could be the case of the following lines:
The case class implements the trait and creates an object factory (among many other things). There is some boilerplate in this implementation that…
View original post 652 more words