Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat. Add mapK on UUIDGenerator #68

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "0.4" // your current series x.y
ThisBuild / tlBaseVersion := "0.5" // your current series x.y

ThisBuild / organization := "tech.ant8e"
ThisBuild / organizationName := "Antoine Comte"
Expand Down Expand Up @@ -35,11 +35,6 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
"org.scalameta" %%% "munit" % "0.7.29" % Test,
"org.typelevel" %%% "munit-cats-effect-3" % "1.0.7" % Test,
"org.scalameta" %%% "munit-scalacheck" % "0.7.29" % Test
),
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem](
"tech.ant8e.uuid4cats.TimestampedUUIDGeneratorBuilder.tech$ant8e$uuid4cats$TimestampedUUIDGeneratorBuilder$$GeneratorState"
)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ package tech.ant8e.uuid4cats
import cats.effect.std.{Mutex, Random, SecureRandom}
import cats.effect.{Async, Clock, Ref}
import cats.syntax.all.*
import cats.~>
import tech.ant8e.uuid4cats.TimestampedUUIDGeneratorBuilder.GeneratorState

import java.util.UUID

trait UUIDGenerator[F[_]] {
def uuid: F[UUID]
def mapK[G[_]](fk: F ~> G): UUIDGenerator[G] = {
new UUIDGenerator[G] {
override def uuid: G[UUID] = fk(UUIDGenerator.this.uuid)
}
}
}

object UUIDGenerator {
Expand Down
16 changes: 16 additions & 0 deletions core/shared/src/test/scala/tech/ant8e/uuid4cats/BuilderSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package tech.ant8e.uuid4cats

import cats.syntax.all.*
import cats.~>
import munit.FunSuite

import java.util.UUID
Expand Down Expand Up @@ -50,6 +52,20 @@ class BuilderSuite extends FunSuite {
assertEquals(obtained, expected)
}

test("UUIDGenerator accepts natural transformations") {
val generator: UUIDGenerator[List] = new UUIDGenerator[List] {
def uuid: List[UUID] = List(
uuid"017F22E2-79B0-7CC3-98C4-DC0C0C07398F",
uuid"017F22E2-79B0-7CC3-98C4-DC0C0C07398F"
)
}
val listToOption = new (List ~> Option) {
override def apply[A](fa: List[A]): Option[A] = fa.headOption
}
val obtained = generator.mapK(listToOption).uuid
assertEquals(obtained, uuid"017F22E2-79B0-7CC3-98C4-DC0C0C07398F".some)
}

implicit class uuidOps(sc: StringContext) {
def uuid(args: Any*): UUID = UUID.fromString(sc.s(args: _*))
}
Expand Down
Loading