// Created on savesnippets.com ยท https://savesnippets.com/GqqCTKbvQOAN4V enum class Status(val label: String, val isFinal: Boolean) { PENDING("Awaiting review", false), ACTIVE("In progress", false), DONE("Completed", true), CANCELLED("Cancelled", true); fun canTransitionTo(target: Status): Boolean = !this.isFinal && this != target } enum class Operation { ADD { override fun apply(a: Int, b: Int) = a + b }, SUBTRACT { override fun apply(a: Int, b: Int) = a - b }, MULTIPLY { override fun apply(a: Int, b: Int) = a * b }, DIVIDE { override fun apply(a: Int, b: Int) = a / b }; abstract fun apply(a: Int, b: Int): Int } fun main() { println(Status.PENDING.canTransitionTo(Status.DONE)) // true println(Status.DONE.canTransitionTo(Status.ACTIVE)) // false (already final) println(Operation.MULTIPLY.apply(6, 7)) // 42 // Standard enum APIs println(Status.values().joinToString { it.label }) println(Status.valueOf("ACTIVE")) }