How to combine two nested lists by summing element‑by‑element in Kotlin

1 Answer

0 votes
fun main() {
    val a = listOf(listOf(1, 2), listOf(3, 9))
	val b = listOf(listOf(4, 8), listOf(5, 6))
    
	println(a)
	println(b)
	
    val merged = a.zip(b) { xs, ys -> xs.zip(ys) { x, y -> x + y } }

    println(merged)
}



/*
run:

[[1, 2], [3, 9]]
[[4, 8], [5, 6]]
[[5, 10], [8, 15]]

*/

 



answered Jan 25 by avibootz

Related questions

...