-
Notifications
You must be signed in to change notification settings - Fork 363
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 modern and performant replacement for Enum.values() #283
Comments
Nice! |
The separate type is useful for potential future additions on a standard library level instead of a language one. E.g. we can potentially extend The main reason to inject supplier is to provide lazy instantiation to be compatible with enums that are being reflectively modified |
@qwwdfsad I'm still not sure that a separate If we will ever want to add Right now because of the |
@nikitabobko First, it would be |
It appears that a reified The reason I ask is that while most cases can just use Enum.entries, we have a helper function like this that isn't possible without a reified API. /** Returns an enum entry with the specified name or `null` if no such entry was found. */
inline fun <reified T : Enum<T>> enumValueOfOrNull(name: String): T? {
return enumValues<T>().find { it.name == name.uppercase(Locale.ENGLISH) }
} |
It will appear in Kotlin 1.9.20. The tracking issue for this function in stdlib is: https://youtrack.jetbrains.com/issue/KT-53154 |
This proposal describes a rationale and a path to migrate from function
values()
provided by each enum type to a collection-based and more predictable abstraction.Text: https://github.com/Kotlin/KEEP/pull/284/files
The text was updated successfully, but these errors were encountered: