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

Provide some conditional helpers #21

Open
nesk opened this issue Oct 30, 2023 · 0 comments
Open

Provide some conditional helpers #21

nesk opened this issue Oct 30, 2023 · 0 comments
Labels
core The core of the library is involved DSL API design and its DSL enhancement New feature or request

Comments

@nesk
Copy link
Owner

nesk commented Oct 30, 2023

We could provide some conditional helpers :

  • ifNotNull
  • ifInstanceOf

Instead of:

if (prop.unwrap() != null) prop { // this: Validatable<SomeClass?>
    constrain { it?.someBool == true }
}

we could write:

prop.ifNotNull { // this: Validatable<SomeClass>
    constrain { it.someBool }
}

We avoid calling unwrap, the receiver is automatically defined, and it's no longer nullable.

Some helpers unrelated to type casting could be useful too:

  • ifNotEmpty (CharSequence and iterables)
  • ifNotBlank
  • ifNotNullOrEmpty
  • ifNotNullOrBlank
@nesk nesk added enhancement New feature or request core The core of the library is involved DSL API design and its DSL labels Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core The core of the library is involved DSL API design and its DSL enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant