0

I have an function in @Dao. Lets call that class DaoClass

abstract fun getData() : Flowable<List<Data>>

Now, I want to check if list of data returned is empty or not. I dug through the DaoClass_Impl (generated at build time) and I found out that the Flowable won't be empty. So,

getData().isEmpty will always return false.

So what I did was getData().singleOrError().map{it.isEmpty()} to return if the returned list is actually empty.

But I am having problem as the value is not getting emitted.

Rahul
  • 4,699
  • 5
  • 26
  • 38
  • Dao provides you with a new version of data, whenever the source of your query is updated. Are you sure you want to transform this stream of datas to Single and not to Flowable to check if the list is empty every time? – Marcin Jedynak Jul 02 '18 at 22:58
  • @MarcinJedynak have to use Observables.zip and for that I need Single. – Rahul Jul 02 '18 at 23:14

1 Answers1

3

You need to check what singleOrError actually does:

Returns a Single that emits the single item emitted by this Flowable, if this Flowable emits only a single item, otherwise if this Flowable completes without emitting any items a NoSuchElementException will be signaled and if this Flowable emits more than one item, an IllegalArgumentException will be signaled.

What you're looking for is firstOrError, which returns just the first value emitted.

Kiskae
  • 24,655
  • 2
  • 77
  • 74