https://kotlinlang.org logo
Title
a

al

06/15/2018, 1:07 AM
Trying the koans, is there a difference between the two lines???
val whatisthis = customers.flatMap { it.orders }.flatMap { it.products }
    val allProducts = customers.flatMap { it.orders.flatMap { it.products } }
Thanks in advance, I did compare and it says they are the same
println(whatisthis == allProducts)
k

karelpeeters

06/15/2018, 8:47 AM
They do pretty much the same, yes.
The first one creates a temporary list with all of the orders first, and then maps that to a list of producs in order of the orders. The second one creates a bunch of temporary lists for each customer's list of products for their orders and combines those.