I have type classes depending on 2 types and one of the type contains the other
sealed trait Version
case class Version1() extends Version
case class Version2() extends Version
case class MyModel1(msg: String, version: Version)
case class MyModel2(msg: String, version: Version)
trait Validate[M, V] {
def run : Boolean
}
object Validators {
implicit object ValidateModel1 extends Validate[MyModel1, Version1] {
override def run: Boolean = true
}
implicit object ValidateModel2 extends Validate[MyModel1, Version2] {
override def run: Boolean = true
}
}
And I would like to call my type classes this way:
object App {
def main(args: Array[String]): Unit = {
val model = MyModel1("Test", Version1())
validate(model)
}
def validate(model: MyModel1) {
import Validators._
val v = implicitly[Validate[MyModel1, model.version.type]]
v.run
}
}
But this doesn't work.
Error:(34, 23) could not find implicit value for parameter e: com.playground.Validate[com.playground.MyModel1,model.version.type] val v = implicitly[Validate[MyModel1, model.version.type]] Error:(34, 23) not enough arguments for method implicitly: (implicit e: com.playground.Validate[com.playground.MyModel1,model.version.type])com.playground.Validate[com.playground.MyModel1,model.version.type]. Unspecified value parameter e. val v = implicitly[Validate[MyModel1, model.version.type]]
Replacing the model.version.type with Version1 works
Any idea how to call my type class by pointing to the Version type from the MyModel1 ?
Feel free to suggest a more explicit title :)
Thank you