Skip to content

Sample how to use declare custom `static` lookups on enums in Kotlin

License

Notifications You must be signed in to change notification settings

andriesfc/business-mapped-enum-sample

Repository files navigation

Handling business mapped values as Enums

Sample how to use and declare custom lookups on enums based business codes.

This enables code patterns such as:

fun main() {
    println(LinkMode.fromCode("bi"))
    println(LinkMode.fromPosition(2))
}

enum class LinkMode(private val code: String, private val position: Int) {

    UNI_DIRECTION("uni", 1),
    NONE("none", 0),
    BI_DIRECTION("bi", 3);

    companion object  {
        val fromPosition = enumFromMapped(LinkMode::position)
        val fromCode = enumFromMapped(LinkMode::code)
    }
}

About

Sample how to use declare custom `static` lookups on enums in Kotlin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages