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

Newtype: validating tuples #824

Open
octavz opened this issue Dec 4, 2021 · 2 comments
Open

Newtype: validating tuples #824

octavz opened this issue Dec 4, 2021 · 2 comments

Comments

@octavz
Copy link

octavz commented Dec 4, 2021

Hi,

object KeyValue extends Newtype[(String, String)]:
  override inline def assertion = //I want to validate that first member is not empty, how do I do this ?

We should have a way to build a custom assertion for any given type.

Thank you

@nartamonov
Copy link

I think currently the design of newtypes does not supports wrapping tuples at compile-time. If we define something like:

type Both = Both.Type
object Both extends Newtype[(Int, String)]

Then compile-time construction of that newtype Both((10, "abc")) fails with:

[error]  Newtype Assertion Failed
[error] Could not validate Assertion at compile-time.
[error] Either use a literal or call "Both.unsafeWrap(Expr[Nothing](scala.Tuple2.apply[Int, String](10, "abc")))"

Macro requires we provide literal value, but we use tuple. Hope this limitation will be removed, because newtypes of tuples is helpful.

@guizmaii
Copy link
Member

@octavz Did you try with assertCustom? See #1218 (comment)

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

3 participants