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 a generic utility for filtering enums #3146

Open
anandwana001 opened this issue Apr 30, 2021 · 0 comments
Open

Create a generic utility for filtering enums #3146

anandwana001 opened this issue Apr 30, 2021 · 0 comments
Labels
enhancement End user-perceivable enhancements. good first issue This item is good for new contributors to make their pull request. Impact: Low Low perceived user impact (e.g. edge cases). Work: Low Solution is clear and broken into good-first-issue-sized chunks. Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Projects

Comments

@anandwana001
Copy link
Contributor

anandwana001 commented Apr 30, 2021

Is your feature request related to a problem? Please describe.
Currently, in all our enum files, we usually use similar items filtering.

Some examples of filtering include:

chapterSummaries.map(ChapterSummary::getChapterPlayState)

Describe the solution you'd like
Generalize filtering which can be used by all the enum.

Describe alternatives you've considered

interface EnumWithKey<T : Enum<T>, K> {
  val T.key: K
}
inline fun <reified T : Enum<T>, K> EnumWithKey<T, K>.getValue(key: K): T {
  return enumValues<T>().find { it.key == key }
    ?: throw IllegalStateException("In the enum ${T::class.java} " +
      "there should be at least one enumeration")
}

Additional context
Look here for learning purpose - https://gist.github.com/programmerr47/e1a62f912c735249c89c3f5c44b6b366#file-enum-kt

@Broppia Broppia added this to To do in Dev Team via automation Jul 29, 2022
@Broppia Broppia added issue_type_infrastructure Impact: Low Low perceived user impact (e.g. edge cases). labels Jul 29, 2022
@BenHenning BenHenning added Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. Z-ibt Temporary label for Ben to keep track of issues he's triaged. issue_user_developer labels Sep 15, 2022
@seanlip seanlip added enhancement End user-perceivable enhancements. and removed issue_type_infrastructure labels Mar 28, 2023
@MohitGupta121 MohitGupta121 added the Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. label Jun 16, 2023
@adhiamboperes adhiamboperes added good first issue This item is good for new contributors to make their pull request. and removed Issue: Needs Clarification Indicates that an issue needs more detail in order to be able to be acted upon. labels Mar 26, 2024
@adhiamboperes adhiamboperes changed the title Generalize Enum Findings Create a generic utility for filtering enums Mar 26, 2024
@adhiamboperes adhiamboperes added Work: Low Solution is clear and broken into good-first-issue-sized chunks. and removed Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. labels Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement End user-perceivable enhancements. good first issue This item is good for new contributors to make their pull request. Impact: Low Low perceived user impact (e.g. edge cases). Work: Low Solution is clear and broken into good-first-issue-sized chunks. Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Projects
Development

No branches or pull requests

6 participants