diff --git a/app/src/main/java/com/mindorks/kotlinFlow/learn/retrofit/parallel/ParallelNetworkCallsViewModel.kt b/app/src/main/java/com/mindorks/kotlinFlow/learn/retrofit/parallel/ParallelNetworkCallsViewModel.kt index 2d92677..08bd082 100644 --- a/app/src/main/java/com/mindorks/kotlinFlow/learn/retrofit/parallel/ParallelNetworkCallsViewModel.kt +++ b/app/src/main/java/com/mindorks/kotlinFlow/learn/retrofit/parallel/ParallelNetworkCallsViewModel.kt @@ -31,10 +31,7 @@ class ParallelNetworkCallsViewModel( users.postValue(Resource.loading(null)) apiHelper.getUsers() .zip(apiHelper.getMoreUsers()) { usersFromApi, moreUsersFromApi -> - val allUsersFromApi = mutableListOf() - allUsersFromApi.addAll(usersFromApi) - allUsersFromApi.addAll(moreUsersFromApi) - return@zip allUsersFromApi + usersFromApi + moreUsersFromApi } .flowOn(Dispatchers.Default) .catch { e -> diff --git a/app/src/main/java/com/mindorks/kotlinFlow/learn/room/RoomDBViewModel.kt b/app/src/main/java/com/mindorks/kotlinFlow/learn/room/RoomDBViewModel.kt index fbdef08..cfee7b3 100644 --- a/app/src/main/java/com/mindorks/kotlinFlow/learn/room/RoomDBViewModel.kt +++ b/app/src/main/java/com/mindorks/kotlinFlow/learn/room/RoomDBViewModel.kt @@ -29,17 +29,14 @@ class RoomDBViewModel(private val apiHelper: ApiHelper, private val dbHelper: Da if (usersFromDb.isEmpty()) { return@flatMapConcat apiHelper.getUsers() .map { apiUserList -> - val userList = mutableListOf() - for (apiUser in apiUserList) { - val user = User( + apiUserList.map { apiUser -> + User( apiUser.id, apiUser.name, apiUser.email, apiUser.avatar ) - userList.add(user) } - userList } .flatMapConcat { usersToInsertInDB -> dbHelper.insertAll(usersToInsertInDB)