diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/xyz/driver/core/core.scala | 6 | ||||
-rw-r--r-- | src/test/scala/xyz/driver/core/CoreTest.scala | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/main/scala/xyz/driver/core/core.scala b/src/main/scala/xyz/driver/core/core.scala index 8c13aeb..1c92423 100644 --- a/src/main/scala/xyz/driver/core/core.scala +++ b/src/main/scala/xyz/driver/core/core.scala @@ -34,13 +34,17 @@ package core { override def toString: String = value } + @SuppressWarnings(Array("org.wartremover.warts.ImplicitConversion")) object Id { implicit def idEqual[T]: Equal[Id[T]] = Equal.equal[Id[T]](_ == _) implicit def idOrdering[T]: Ordering[Id[T]] = Ordering.by[Id[T], String](_.value) + sealed trait Mapper[E, R] object Mapper { - def apply[A, B]: (Id[A] => Id[B]) = (id: Id[A]) => Id[B](id.value) + def apply[E, R] = new Mapper[E, R] {} } + implicit def convertRE[R, E](id: Id[R])(implicit ev: Mapper[E, R]): Id[E] = Id[E](id.value) + implicit def convertER[E, R](id: Id[E])(implicit ev: Mapper[E, R]): Id[R] = Id[R](id.value) } final case class Name[+Tag](value: String) extends AnyVal { diff --git a/src/test/scala/xyz/driver/core/CoreTest.scala b/src/test/scala/xyz/driver/core/CoreTest.scala index e210887..520fe8e 100644 --- a/src/test/scala/xyz/driver/core/CoreTest.scala +++ b/src/test/scala/xyz/driver/core/CoreTest.scala @@ -45,9 +45,7 @@ class CoreTest extends FlatSpec with Matchers with MockitoSugar { final case class Z(id: Id[Z]) implicit val xy = Id.Mapper[X, Y] - implicit val yx = Id.Mapper[Y, X] implicit val yz = Id.Mapper[Y, Z] - implicit val zy = Id.Mapper[Z, Y] // The real test is that the following statements compile: val x = X(Id("0")) |