Saturday 15 March 2014

Using Lenses on Scala Regular Classes -


The most popular JSON libraries for Scala have the ability to sort and deserialize the classes.

Unfortunately, unless Scala 2.11 is released, there may be a case class (22 max) restrictions on the number of parameters. As an alternative solution to go to this limit, it is possible to use regular classes instead. (for example:).

However, this loses the benefits of the case classes. For example, there is no auto generated copy constructor, and the lenses do not work with regular classes, so manipulation in the structure becomes very cumbersome (unless each field in each category is a var Does not make it, leaving the benefits of irreversible).

Do regular classes treat more like classes, for example, lenses will also work on them?

If you are using a lens in any way, just nest your case classes . You will have more potential to reuse the data, and not the main reason for nests is to avoid monsters like

  record.copy (person = record.person.copy ( Name = record.person) .name.capitalize))   

that (roughly) resolves if you use the lens JSON can control the nested classes.

No comments:

Post a Comment