how to Zip 2 lists with different sizes and display all elements inside lazy column?

Viewed 38

The current problem

val todayRoute = selectRouteViewModel.TodayRoute.collectAsState().value. // 6 elements
val collected = listOf(CompletedRoute(id = 31, name = "Oxfam", completed = 1, arrived = 1)) // 1 element

val route = todayRoute.selectRoute.zip(collected)

val ids = route.first.id + " " + route.second.id
 
print(ids) // 21 31

todayRoute has 6 elements, collected has 1 element

I want to show all elements in todayRoute regardless of list size

1 Answers

zip, by default, the your route collection contains Pairs of source collection elements with the same index. The size of your route collection equals the minimum size of your resource collections. So the size of the route collection will be 1 and will ignore the remaining 5 values ​​while zipping.

image for zip logic

If you want to get all 7 items, I can suggest you to create a new collection and add it there.

Related