Presently if I have to define a nested/hierarchal Map something like Map<String, Map<String, Map<String, String>>>
, I have to separately define each nested map separately and use them to manually build the hierarchy. Is there a simpler way to declare and define such maps? Something similar to what I can do in Javascript.
PS: new to Kotlin
Javascript example (Hypothetical Example).
var schema = {
"US": {
"WA": {
"Seattle": "Pike Street"
}
},
"IN" : {
"Karnataka": {
"Bangalore" : "MG Road"
}
}
};
Kotlin:
val WA_CITY_TO_ST_MAP = mapOf(
"Seattle" to "",
"Redmond" to "1st Ave"
)
val KARNATAKA_CITY_TO_ST_MAP = mapOf("Bangalore" to "MG Road")
val US_STATE_TO_CITIES_MAP = mapOf("WA" to WA_CITY_TO_ST_MAP)
val IN_STATES_TO_CITIES_MAP = mapOf("Karnataka" to KARNATAKA_CITY_TO_ST_MAP)
val schema = mapOf("US" to US_STATE_TO_CITIES_MAP, "IN" to IN_STATES_TO_CITIES_MAP)