1

In my expression, even takeUntil is true/false, subscribe method is emitting all the list items, which should stop once takeUntil is true right?

Observable.fromIterable(countryResponseList.withIndex())
  .subscribeOn(Schedulers.io())
  .observeOn(Schedulers.io())
  .takeUntil((index,item) -> item.getId() == currentCountryCodeId)
  .subscribe((index,item) -> run{
     Log.d("items and index", " ${item} and ${index}")
  })

What i need is to get the current index, when the expressions match( item.getId() == currentCountryCodeId) each other and the RxJava expression should stop continuing. I don't know how to do that, any help appreciated. I also found forEachWhile, will that suit this situation?

SkunkSpinner
  • 11,429
  • 7
  • 40
  • 53
Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
  • `takeUntil` takes only one parameter, how you can pass index & item ? are you sure that this code compile ? – bubbles Oct 30 '19 at 14:22

1 Answers1

1

I'm not sure you want to stop iterating countryResponseList.withIndex(). If so, the upstream should be run on the same thread with takeUntil.

Hope underlying is what you want. If not, how about describe more in detail?

Observable.fromIterable(countryResponseList.withIndex())
  .takeUntil((index,item) -> item.getId() == currentCountryCodeId)
  .subscribeOn(Schedulers.io())
  .observeOn(Schedulers.io())
  .subscribe((index,item) -> run{
     Log.d("items and index", " ${item} and ${index}")
  })
MinseongPark
  • 178
  • 6