``` val pickableState = try { Pickable...
# announcements
m
Copy code
val pickableState = try {
            PickableState.valueOf(state)
        } catch (ex: Exception){
            null
        }
is there a better way to check if a string is present in ENUM?
j
I'd do:
val pickableState: PickableState? = PickableState.values().find{it.name == state}
m
.values will give you all values, right, is there a better way?
j
A better way to achieve what? Could you rephrase your question?
m
you could incapsulate your recurring logic in a top-level generic function:
Copy code
inline fun <reified E : Enum<E>> enumIsPresent(name: String): Boolean {
    return try {
        enumValueOf<E>(name)
        true
    } catch (e: Exception) {
        false
    }
}