Currently we have `enumValues<T>(): Array&lt...
# stdlib
r
Currently we have
enumValues<T>(): Array<T>
and
enumValueOf<T>(name: String): T
for enums. It would be nice if there was also
enumValueAt<T>(ordinal: Int): T
. It's pretty easy to work around with
enumValues()[ordinal]
, so not a huge deal, but it feels a bit clunky. Another nice to have for would be something like
enumSize<T>(): Int
. Again, easy to work around with
enumValues().size
, but same argument as above.
7
e
maybe `enumValueOfOrNull`/`enumValueAtOrNull` too?
5
r
Indeed, that would be in line with the rest of the stdlib.
j
you will find that caching your enums into an array in the campanion object sort of does both but also cures an endemic performance hit in more recent jvm's.
k
Well for JVM it will be perfectly fine. But I can imagine that for stdlib compatibility with other languages it may not fit very well. I thought about creating live template for generating this kind of functions but It will not make big difference for only few usages in project.