This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class EnumConverter<in V, E: Enum<E>>( | |
| private val valueMap: Map<V, E> | |
| ) { | |
| fun fromValue(value: V): E? = valueMap[value] | |
| fun fromValue(value: V?, default: E): E = valueMap[value] ?: default | |
| } | |
| inline fun <V, reified E: Enum<E>> buildValueMap(keySelector: (E) -> V): Map<V, E> = | |
| enumValues<E>().associateBy(keySelector) |