mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-21 13:23:05 +01:00
refactoring
This commit is contained in:
@@ -1,25 +1,22 @@
|
||||
|
||||
package com.lbs.common
|
||||
|
||||
import scala.collection.generic.CanBuildFrom
|
||||
import scala.language.{higherKinds, implicitConversions}
|
||||
|
||||
trait ModelConverters {
|
||||
|
||||
trait CollectionConverter[-In, Out] {
|
||||
def convert[Z <: In, Col[X] <: Iterable[X]](col: Col[Z])(implicit bf: CanBuildFrom[Col[Z], Out, Col[Out]]): Col[Out]
|
||||
}
|
||||
|
||||
trait ObjectConverter[-In, Out] {
|
||||
def convert[Z <: In](any: Z): Out
|
||||
}
|
||||
|
||||
implicit class CollectionOps[From, Col[X] <: Iterable[X]](col: Col[From]) {
|
||||
def mapTo[To](implicit converter: CollectionConverter[From, To], bf: CanBuildFrom[Col[From], To, Col[To]]): Col[To] = converter.convert(col)
|
||||
trait ObjectConverter[-In, +Out] {
|
||||
def convert(any: In): Out
|
||||
}
|
||||
|
||||
implicit class ObjectOps[From](anyRef: From) {
|
||||
def mapTo[To](implicit converter: ObjectConverter[From, To]): To = converter.convert(anyRef)
|
||||
}
|
||||
|
||||
implicit def sequenceConverters[From, To](implicit objectConverter: ObjectConverter[From, To]): ObjectConverter[Seq[From], Seq[To]] = {
|
||||
collection: Seq[From] => {
|
||||
collection.map(objectConverter.convert)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user