<@U0LBJSHH9> Here is a potential alternative solut...
# announcements
r
@javidev Here is a potential alternative solution as @agomez was pointing out regarding using
tailrec
and immutable maps. May be buggy but thought it illustrated his point and may give you more to think about.
Copy code
tailrec fun loop(list: List<String>, acc: Pair<String, Any>): Map<String, Any> =
        when {
            list.isEmpty() -> mapOf(acc)
            else -> {
                val tail = list.drop(1)
                loop(tail,
                        if (tail.isEmpty()) acc
                        else Pair(tail[0], mapOf(acc)))
            }
        }

fun main(args: Array<String>): Unit {
    val s = "a.b.c.d = 20" //hacky cleanup, should be done with proper parsers
    val exp = s.replace(" ", "").split("=")
    val lhs = exp[0].split(".").reversed()
    val rhs = exp[1]
    val result = loop(lhs, Pair(lhs[0], rhs))
    println(result) // {a={b={c={d=20}}}}
}