2

I have a two flows. One is a list of products updated by network calls and the second flow is a list of products read from a local SQLite database (using Room).

Storefront flow

Get all products  --- Network ---\
Search products   --- Network ------- List<Products> ---> data class Cart ---> Flow<List<Product>>
Filter products   --- Network ---/

Cart flow

Load Cart from SQLite --- Room ------ Flow ---> Flow<List<Product>>

The List<Product> read from SQLite will have the latest quantity, read using a flow. And I would like this quantity to be reflected to the List<Product> used in the Storefront.

Question

  1. How to I transform the storefront flow to have the latest quantity in accordance with the product and quantity in the cart.
clamentjohn
  • 3,417
  • 2
  • 18
  • 42
  • Take a look at this. Might be the answer to your task: https://stackoverflow.com/questions/57693392/merging-kotlin-flows – Erik Schmidt Aug 02 '21 at 12:25
  • 1
    I'd recommend stepping back and looking at this differently and try to rearchitect your solution to include a single source of truth. Right now you've got data coming from two places and you're planning on merging them. https://medium.com/@sina.rahimi/single-source-of-truth-with-mvvm-retrofit2-livedata-rxjava-and-room-in-repository-pattern-f5304f39175 – SamCosta1 Aug 02 '21 at 13:10

0 Answers0