diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-21 21:04:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-21 21:04:40 -0500 |
commit | 9dead411fb4fb170ab2372a50ed5a61ce853499b (patch) | |
tree | eeef9877c0be077b1a308c92be6bbe622304badc /src/main/scala/xyz/driver/core | |
parent | 687919e7c163e1ff8a002f1a2c24e4b37f75f20d (diff) | |
parent | 3c22528e7f99e4b16327d6308c67b4be49d89efe (diff) | |
download | driver-core-9dead411fb4fb170ab2372a50ed5a61ce853499b.tar.gz driver-core-9dead411fb4fb170ab2372a50ed5a61ce853499b.tar.bz2 driver-core-9dead411fb4fb170ab2372a50ed5a61ce853499b.zip |
Merge pull request #13 from drivergroup/symmetric-id-mapper
Make id type mappers bidirectional
Diffstat (limited to 'src/main/scala/xyz/driver/core')
-rw-r--r-- | src/main/scala/xyz/driver/core/core.scala | 6 |
1 files changed, 5 insertions, 1 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 { |