Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2020-2025 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cats.effect.std

import cats.data._
import cats.effect._

import java.util.UUID

object ImplicitPriorityPlayground {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the way that we've done this in the past is to structure compilation tests as actual test suites with a tautological tests (i.e. the test always passes at runtime provided it compiles). MUnit doesn't provide anything more elaborate than that, sadly.


def foo[F[_]: UUIDGen]: F[UUID] = UUIDGen[F].randomUUID

SecureRandom.javaSecuritySecureRandom[IO].flatMap { implicit random =>
foo[Kleisli[IO, String, *]].run("hello world")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package cats.effect.std

import cats.effect.kernel.Sync

private[std] trait UUIDGenCompanionPlatform extends UUIDGenCompanionPlatformLowPriority
private[std] trait UUIDGenCompanionPlatform extends UUIDGenCompanionPlatformMediumPriority

private[std] trait UUIDGenCompanionPlatformLowPriority {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cats.effect.kernel.Sync

import java.util.UUID

private[std] trait UUIDGenCompanionPlatform extends UUIDGenCompanionPlatformLowPriority
private[std] trait UUIDGenCompanionPlatform extends UUIDGenCompanionPlatformMediumPriority

private[std] trait UUIDGenCompanionPlatformLowPriority {

Expand Down
19 changes: 11 additions & 8 deletions std/shared/src/main/scala/cats/effect/std/UUIDGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import cats.data.{
OptionT,
WriterT
}
import cats.implicits._
import cats.syntax.all._

import java.util.UUID

Expand Down Expand Up @@ -118,6 +118,16 @@ object UUIDGen extends UUIDGenCompanionPlatform {
]: UUIDGen[IndexedReaderWriterStateT[F, E, L, S, S, *]] =
UUIDGen[F].mapK(IndexedReaderWriterStateT.liftK)

private[std] final class TranslatedUUIDGen[F[_], G[_]](self: UUIDGen[F])(f: F ~> G)
extends UUIDGen[G] {
override def randomUUID: G[UUID] =
f(self.randomUUID)

}
}

private[std] trait UUIDGenCompanionPlatformMediumPriority
extends UUIDGenCompanionPlatformLowPriority {
implicit def fromSecureRandom[F[_]: Functor: SecureRandom]: UUIDGen[F] =
new UUIDGen[F] {
override final val randomUUID: F[UUID] =
Expand All @@ -137,11 +147,4 @@ object UUIDGen extends UUIDGenCompanionPlatform {
new UUID(msb, lsb)
}
}

private[std] final class TranslatedUUIDGen[F[_], G[_]](self: UUIDGen[F])(f: F ~> G)
extends UUIDGen[G] {
override def randomUUID: G[UUID] =
f(self.randomUUID)

}
}
Loading