I am using a Generic Mapper to map a Model from a DBModel in scala 2.11
it has a method defined as:
def fromModelToDBModel(m: T) : R
where T is the type of the Model and R is the type of the DBModel.
This method is implemented the same way in almost all inheriting objects, ie:
override def fromModelToDBModel(p: RawModel): RawDBModelV1 = {
val values = RawModel.unapply(p).get
val makeDBModel = (RawDBModelV1.apply _).tupled
makeDBModel(values)
}
Is it possible to somehow define a generic object in the base Trait, so I can call apply/unapply on it?
example of the logic I would like to implement:
def fromModelToDBModel(m: T) : R = {
val values = Object[T].unapply(p).get
val makeDBModel = (Object[R].apply _).tupled
makeDBModel(values)
}
This would eliminate the need for writing every mapper individually, making the code more DRY.