I\'m trying to find the best way to do a \'reverse lookup\' on an enum in Kotlin. One of my takeaways from Effective Java was that you introduce a static map inside the enum
Came up with a more generic solution
inline fun > findEnumConstantFromProperty(predicate: (T) -> Boolean): T? = T::class.java.enumConstants?.find(predicate)
Example usage:
findEnumConstantFromProperty { it.value == 1 } // Equals Type.A