Q:

Kotlin function to print all of an Enum's ordinal/name pairs

Something about Enums is confusing me.   I'd like a function to "know" about all the possible Enum ordinal/name mappings, but passing my enum class to a function isn't working right.   
fun printEnumOrdinalAndNames(targetEnumType:???)  
I can hack around it on the calling side with
println(MY_ENUM_TYPE.values().map { it.ordinal to it.name }.toMap())
but am not sure if I can somehow pass in a MY_ENUM_TYPE::class or similar, I can't get the function signature right to accept any Enum.   printEnumOrdinalAndNames(MY_ENUM_TYPE) won't compile because it isn't valid syntax. 

A:

You can write a function with a reified type to do this on any Enum.  Once you have the class, you can map its enumContstants to whatever you'd like (a Map<String,Int> in this case), or modify it to print them if you'd like. 
inline fun <reified T : Enum<*>> namesAndOrdinalsOf(): Map<String,Int> =
    T::class.java.enumConstants.map {
        it.name to it.ordinal
    }.toMap()

Edit: I had no idea that enumValues<T>() existed (thanks @Slaw), you can rewrite it like this, as it is simpler:
inline fun <reified T : Enum<T>> namesAndOrdinalsOf(): Map<String,Int> =
    enumValues<T>().map {
        it.name to it.ordinal
    }.toMap()

And to use it:
enum class Things {
    Grapes,
    Chairs,
    Spectacles
}

fun main() {
    println(namesAndOrdinalsOf<Things>())
}
// Prints: {Grapes=0, Chairs=1, Spectacles=2}

