mapOf(“key” to ()->Unit = {})
# announcements
r
mapOf(“key” to ()->Unit = {})
s
When I try to do this, Kotlin has a fit, the error is "getter or setter expected"
Copy code
val flagMap = mapOf(
    "a" to () -> Unit {}
)
I want it to be something like: mapOf( "a" to () -> { return aFlags } )
e
it may be typed '() -> Nothing' instead, "a" to { aFlags } ?
s
yes that works great, thanks
it actually suggests that if i dont use the function call and just map it to the list, that its type of Map<Pair<Int, Int>>
just "a" to aflags vs "a" to {aflags}
c
You could also just make them functions in the class and the map would be
a to ::aFlags
and then you don't have to worry about all the logic being crammed into the map setup.
And at retrieval:
map[inputFlag]?.invoke()