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

Create new guard noneExcept(var1, var2, ...) #68

Open
zambrovski opened this issue Aug 23, 2020 · 5 comments
Open

Create new guard noneExcept(var1, var2, ...) #68

zambrovski opened this issue Aug 23, 2020 · 5 comments
Assignees
Labels
Type: enhancement New feature or request

Comments

@zambrovski
Copy link
Member

zambrovski commented Aug 23, 2020

Scenario

I want to be able to specify a whitelist of variables that needs to be present in the provided scope. No other variables are allowed.

Something like:

val conditions = listOf(
  noneExcept(VAR1, VAR2),
  hasValue(VAR1, "foo"),
  matches(VAR2) { it > 234 }
)

The problem with the noneExcept condition is, that it can not be defined on a single VariableFactory and thus is not matching the abstract class VariableFactoryCondition<T>.

Alternative approach would be to define a new Guard, which is checking conditions on the whole context (like in this case).

@zambrovski zambrovski self-assigned this Aug 23, 2020
@zambrovski zambrovski added the Type: enhancement New feature or request label Aug 23, 2020
@zambrovski
Copy link
Member Author

What do you think, @jangalinski ?

@jangalinski
Copy link
Contributor

like it ... but "noneExcept" ... would sound better with "hasOnly" or stlt

@zambrovski
Copy link
Member Author

zambrovski commented Aug 25, 2020

The problem is the signature. hasOnly(varargs factories: VariableFactory) means that the return type of this method is not an VariableGuardCondition<T>, because of:

abstract class VariableGuardCondition<T>(
  internal val variableFactory: VariableFactory<T>,
  internal val local: Boolean = false
) { ... }

It is not a guard on one factory, but on the entire context....

@jangalinski
Copy link
Contributor

ok.

@zambrovski
Copy link
Member Author

So it is meant as a question, I don't have a solution yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants