如何转换成精致型?

How to convert into refined type?

我正在使用库 https://github.com/fthomas/refined 并想将 java.util.UUID 转换为精炼的 Uuid
如何将 java.util.UUID 转换为精炼的 Uuid

更新

我有以下 http 路由:

  private val httpRoutes: HttpRoutes[F] = HttpRoutes.of[F] {
    case GET -> Root / UUIDVar(id) =>
      program.read(id)

读取函数定义如下:

  def read(id: Uuid): F[User] =
    query
      .read(id)
      .flatMap {
        case Some(user) =>
          Applicative[F].pure(user)
        case None =>
          ApplicativeError[F, UserError].raiseError[User](UserNotRegistered)
      }

编译器抱怨:

type mismatch;
[error]  found   : java.util.UUID
[error]  required: eu.timepit.refined.string.Uuid
[error]       program.read(id)
[error]         

       ^

这里是将java.util.UUID转换成eu.timepit.refined.api.Refined[String, eu.timepit.refined.string.Uuid]

import java.util.UUID    
import eu.timepit.refined.string.Uuid
import eu.timepit.refined.api.Refined

val uuid: UUID = UUID.fromString("deea44c7-a180-4898-9527-58db0ed34683")

val uuid1: String Refined Uuid = Refined.unsafeApply[String, Uuid](uuid.toString)