**This is what I want:**

> 
> 1. Check if I have data about products in database.
> 2. If I have data I run Single to get data from DB.
> 3. If not I run Single for get data from backend
> 4. If I get response I want to save data in DB using Completable.
> 5. After saving data I want to map values from step 2 or 3 to view model
> 6. In result I want to send data to activity.
> 
> 
> 

This is what I have now:

```
checkProductsInDBUseCase.run()
                .flatMap {
                    if (it) {
                        getProductsFromDBUseCase.run()
                    } else {
                        getProductsUseCase.run(3)
                    }
                }.map {
                    it.products.map { item -> item.toViewModel() }
                }
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeBy(
                        onSuccess = {
                            view.showBikes(it)
                        },
                        onError = {
                            view.showBikesError(it.message.toString())
                        }
                ).addTo(disposables)

```

Between flat map and map I need to run `saveDataUseCase(it)`, but I don't know how to pass `it`from completable to map. Any ideas?