I have an observable that gets a list of things, t...
# rx
b
I have an observable that gets a list of things, then for each item I get, I need to do a network call. That network call will give me an onSuccess or onError. That is all fine and dandy. What I'm having an issue is when I get an item, I'm checking a jsonarray for "error". If it finds an error I want that observable to be discarded. So far my code looks like this:
Copy code
fun refreshHoldings(convert: String) {
        this.convert = convert
        db.getHoldings()
                .observeOn(<http://Schedulers.io|Schedulers.io>())
                .map { items -> Observable.fromIterable(items).flatMap{ repo.insertCoinById(it.id, convert)} }
    }
For the insert part, I have this:
Copy code
fun insertCoinById(id: String, convert: String = "usd") =
        api.getCoinById(id, convert)
                .subscribeOn(<http://Schedulers.io|Schedulers.io>())
                .map(this::convertToCoin)
                .filter { it.id != "" } //id is set to "" if there is an error
                .doOnNext { db.insertCoin(it) } //If there is an error I don't want to insert it.
I'm not sure how I can discard a result