harness.pk.StringId.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harness-pk_3 Show documentation
Show all versions of harness-pk_3 Show documentation
Miscellaneous libraries/utilities for Scala.
package harness.pk
import harness.core.*
import harness.schema.*
import harness.zio.*
import java.util.UUID
import zio.*
trait StringId { self =>
final case class Id(value: String) {
override def toString: String = s"${Id.tag.toHTag.prefixNoneNoGenerics}($value)"
}
object Id {
implicit val stringEncoder: StringEncoder[Id] = StringEncoder.string.imap[Id](_.value)
implicit val stringDecoder: StringDecoder[Id] = StringDecoder.string.map(Id(_))
implicit val iMap: IMap[String, Id] = IMap.make[String](Id(_))(_.value)
implicit val tag: Tag[Id] = self.getClass.toHTag.withType[Id].toTag
implicit val rawSchema: RawSchema[Id] = RawSchema.encodedStringSchema
implicit val jsonSchema: JsonSchema[Id] = JsonSchema.encodedStringSchema
}
inline def apply(value: String): Id = Id(value)
def gen: Id = Id(UUID.randomUUID().toString)
def genZio: UIO[Id] = Random.nextUUID.map(uuid => Id(uuid.toString))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy