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

Custom validators with specific datatypes #59

Open
andyczerwonka opened this issue Nov 3, 2020 · 0 comments
Open

Custom validators with specific datatypes #59

andyczerwonka opened this issue Nov 3, 2020 · 0 comments

Comments

@andyczerwonka
Copy link

andyczerwonka commented Nov 3, 2020

Given the following silly rule, but just to illustrate:

  case class Id(id: UUID = UUID.randomUUID())
  object Id {
    implicit val validations: Validator[Id] = Validator[Id]
      .rule[UUID](_.id, !_.toString.isEmpty, "is required")
  }

This won't compile (can't create the typeclass because of java.util.UUID. There are other examples, see #51 (comment), which was handled simply by changing the HashMap to a Map. In this case, it's not feasible.

For many code bases that uses UUID's for identity keys. Should we handle this case by manually registering a typeclass for this type? Something like:

  implicit def uuidValidator(implicit v: Validator[String]): Validator[UUID] =
    (id: UUID) => v.validate(id.toString)
@andyczerwonka andyczerwonka changed the title validators with specific datatypes cannot be created Custom validators with specific datatypes Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant