diff --git a/.gitignore b/.gitignore index 87e7b850..2061a4ba 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ target/ tags .metals .bloop +project/metals.sbt diff --git a/build.sbt b/build.sbt index 26f021ac..f283654c 100644 --- a/build.sbt +++ b/build.sbt @@ -13,7 +13,6 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) name := "fuuid" ) - lazy val coreJS = core.js lazy val coreJVM = core.jvm @@ -95,12 +94,10 @@ lazy val contributors = Seq( lazy val commonSettings = Seq( organization := "io.chrisdavenport", - scalaVersion := "2.13.0", - crossScalaVersions := Seq(scalaVersion.value, "2.12.8"), - - scalacOptions += "-Yrangepos", + scalaVersion := "2.13.1", + crossScalaVersions := Seq(scalaVersion.value, "2.12.10"), - addCompilerPlugin("org.typelevel" % "kind-projector" % "0.10.3" cross CrossVersion.binary), + addCompilerPlugin("org.typelevel" % "kind-projector" % "0.11.0" cross CrossVersion.full), addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"), libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value, diff --git a/modules/core/src/main/scala/io/chrisdavenport/fuuid/FUUIDGen.scala b/modules/core/src/main/scala/io/chrisdavenport/fuuid/FUUIDGen.scala new file mode 100644 index 00000000..dd369bb2 --- /dev/null +++ b/modules/core/src/main/scala/io/chrisdavenport/fuuid/FUUIDGen.scala @@ -0,0 +1,46 @@ +package io.chrisdavenport.fuuid + +import java.util.UUID +import cats.implicits._ +import cats.effect.Sync + +/** + * This trait is an F-algebra representation of the ability to generate FUUID's. + * + * At some edge a Sync is required in order to populate the randomness when required. + */ +@scala.annotation.implicitNotFound("""Cannot find implicit value for FUUIDGen[${F}]. +Building this implicit value depends on having an implicit +Sync[${F}] or some equivalent type.""") +trait FUUIDGen[F[_]]{ + /** + * Creates a Random FUUID + */ + def random: F[FUUID] + /** + * Creates an FUUID from a String, if it is valid + */ + def fromString(s: String): F[FUUID] + /** + * Creates an FUUID from a UUID + */ + def fromUUID(uuid: UUID): F[FUUID] + /** + * Creates a new name-based UUIDv5. NOTE: Not implemented for Scala.js! + **/ + def nameBased(namespace: FUUID, name: String): F[FUUID] +} + +object FUUIDGen { + def apply[F[_]](implicit ev: FUUIDGen[F]): FUUIDGen[F] = ev + + // Sync f => class FUUIDGen f + implicit def instance[F[_]: Sync]: FUUIDGen[F] = new SyncFUUIDGen[F] + + private class SyncFUUIDGen[F[_]: Sync] extends FUUIDGen[F]{ + def random: F[FUUID] = FUUID.randomFUUID[F] + def fromString(s: String): F[FUUID] = FUUID.fromStringF[F](s) + def fromUUID(uuid: UUID): F[FUUID] = FUUID.fromUUID(uuid).pure[F] + def nameBased(namespace: FUUID, name: String): F[FUUID] = FUUID.nameBased[F](namespace, name) + } +}