gets you the value of key3 which is in a nested ma...
# codereview
b
gets you the value of key3 which is in a nested map (jackson objectmapper prerequisite not included)
k
Your example code doesn't even compile for me, I think because
T
is wrong? Or is
value
not supposed to be something like
mapOf("x" to mapOf("y" to mapOf("z" to 5)))
?
But if I understand correctly this can be rewritten with `fold`:
Copy code
private fun traverse(map: Map<*, *>, vararg keys: String): Any? =
        keys.fold(map as Any?) { m, k ->
            (m as? Map<*, *>)?.get(k) ?: return null
        }
b
mine definitely works but that looks nice too
you might not have been passing the map as <*, *>
k
Yeah probably, but the way
T
is used here isn't right at all.
b
yes it could be ‘Any?’ without generics
i was drinking when i made it
🤟 1
1