Elegant way to determine if value is any of a few enum types? [on hold]












-4














Let say I have an enum called UserRole which contains 100 roles. I am currently checking roles this way:



guard userRole == .admin 
|| userRole == .recruiter
|| ....
else {
...
}


The thing I am repeating all the time is this:



userRole ==


Isn't there something shorter, like:



guard userRole == (.admin | .recruiter | ... )
else {
...
}









share|improve this question







New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, alecxe, 200_success, Zeta, janos Dec 29 '18 at 7:10


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, alecxe, 200_success, Zeta, janos

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Like this?
    – esote
    Dec 28 '18 at 21:08












  • Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Zeta
    Dec 29 '18 at 5:40
















-4














Let say I have an enum called UserRole which contains 100 roles. I am currently checking roles this way:



guard userRole == .admin 
|| userRole == .recruiter
|| ....
else {
...
}


The thing I am repeating all the time is this:



userRole ==


Isn't there something shorter, like:



guard userRole == (.admin | .recruiter | ... )
else {
...
}









share|improve this question







New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, alecxe, 200_success, Zeta, janos Dec 29 '18 at 7:10


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, alecxe, 200_success, Zeta, janos

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Like this?
    – esote
    Dec 28 '18 at 21:08












  • Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Zeta
    Dec 29 '18 at 5:40














-4












-4








-4







Let say I have an enum called UserRole which contains 100 roles. I am currently checking roles this way:



guard userRole == .admin 
|| userRole == .recruiter
|| ....
else {
...
}


The thing I am repeating all the time is this:



userRole ==


Isn't there something shorter, like:



guard userRole == (.admin | .recruiter | ... )
else {
...
}









share|improve this question







New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Let say I have an enum called UserRole which contains 100 roles. I am currently checking roles this way:



guard userRole == .admin 
|| userRole == .recruiter
|| ....
else {
...
}


The thing I am repeating all the time is this:



userRole ==


Isn't there something shorter, like:



guard userRole == (.admin | .recruiter | ... )
else {
...
}






swift






share|improve this question







New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Dec 28 '18 at 20:46









J. Doe

931




931




New contributor




J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, alecxe, 200_success, Zeta, janos Dec 29 '18 at 7:10


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, alecxe, 200_success, Zeta, janos

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by πάντα ῥεῖ, alecxe, 200_success, Zeta, janos Dec 29 '18 at 7:10


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, alecxe, 200_success, Zeta, janos

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    Like this?
    – esote
    Dec 28 '18 at 21:08












  • Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Zeta
    Dec 29 '18 at 5:40














  • 1




    Like this?
    – esote
    Dec 28 '18 at 21:08












  • Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Zeta
    Dec 29 '18 at 5:40








1




1




Like this?
– esote
Dec 28 '18 at 21:08






Like this?
– esote
Dec 28 '18 at 21:08














Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Zeta
Dec 29 '18 at 5:40




Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Zeta
Dec 29 '18 at 5:40















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Сан-Квентин

Алькесар

Josef Freinademetz