All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.kodeworks.kvarg.model.HasId.scala Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package no.kodeworks.kvarg.model

import shapeless._

trait HasId[HasIdable] {
  def id(hasIdable: HasIdable): Option[Long]

  def withId(hasIdable: HasIdable, id: Option[Long]): HasIdable
}

object HasId {
  implicit def instance[HasIdable](implicit
                                   idLens0: MkFieldLens.Aux[HasIdable, Witness.`'id`.T, Option[Long]]
                                  ): HasId[HasIdable] =
    new HasId[HasIdable] {
      val idLens = lens[HasIdable] >> 'id

      override def id(hasIdable: HasIdable): Option[Long] =
        idLens.get(hasIdable)


      override def withId(hasIdable: HasIdable, id: Option[Long]): HasIdable =
        idLens.set(hasIdable)(id)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy