Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andyglow/caseclass-evolution
Scala Case Class Extendable
https://github.com/andyglow/caseclass-evolution
case-class evolution extend scala
Last synced: 19 days ago
JSON representation
Scala Case Class Extendable
- Host: GitHub
- URL: https://github.com/andyglow/caseclass-evolution
- Owner: andyglow
- Created: 2019-08-03T06:29:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-14T20:14:30.000Z (over 3 years ago)
- Last Synced: 2024-10-03T08:12:49.698Z (about 1 month ago)
- Topics: case-class, evolution, extend, scala
- Language: Scala
- Size: 59.6 KB
- Stars: 9
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Scala Case Class Evolution
--------------------------[![Build Status](https://cloud.drone.io/api/badges/andyglow/caseclass-evolution/status.svg)](https://cloud.drone.io/andyglow/caseclass-evolution)
[![codecov](https://codecov.io/gh/andyglow/caseclass-evolution/branch/master/graph/badge.svg)](https://codecov.io/gh/andyglow/caseclass-evolution)EXPERIMENTAL
============With Scala developer can't extends case classes.
That's an axiom.
But sometimes, especially if you, like me, work with big data, you really want scala could do that.
Otherwise you stuck with doing boilerplate like this.```scala
case class User(
id: String,
firstName: String,
middleName: Option[String],
lastName: String,
... // ton of properties
)case class BankUser(
id: String,
firstName: String,
middleName: Option[String],
lastName: String,
... // ton of propertiesbank: String,
bankAccount: String,
bankSwift: String,
bankAccountCreatedAt: LocalDate
)
```With the library I wanted to introduce this boilerplate gets reduced.
```scala
@evolve(User)
case class BankUser(
bank: String,
bankAccount: String,
bankSwift: String,
bankAccountCreatedAt: LocalDate)
```Sounds good so far?
The resulted class definition will be the same as an example from previous snippet.
With even one helper method added `withUser`, which takes a `User` and applies it to `BankUser`.There also 2 extra features.
- we can reduce case class definition by removing unnecessary fields
- we can rename fields```scala
@evolve(from = User, removed = Set("middleName"), renamed = Map("id" -> "userId"))
case class UserV2()
```Even though it may look cool, there is a huge obstacle.
*IDE support is absent*. Code in IDE will be all highlighted and look ugly.### Apache Spark
It can be used with Apache Spark to define schemas. `Dataset` API.
Also with a little trick it might be used with `Frameless`.
In order to use it with `Frameless` one need to build model separately from code using it.
Consider separate module or separate library.TODO
----
- same name, but type changed scenario