android-ktx icon indicating copy to clipboard operation
android-ktx copied to clipboard

Add empty check functions

Open suhtai opened this issue 7 years ago • 3 comments

Extends Cursor to provide functions to check i the cursor is empty or not

Usage

if(cursor.isEmpty()) {
  // we can show an empty screen
}

if(cursor.isNotEmpty()) {
  // We got data
}

suhtai avatar Jun 08 '18 15:06 suhtai

I don't think we want to use count because it requires that the query backing the cursor traverse its entire result set. So if you query for a million items but end up only taking 5 calling count will traverse over the entire million to return an accurate number.

JakeWharton avatar Jun 08 '18 16:06 JakeWharton

Good point, would isBeforeFirst be a better call? I do hope not many people have 5 million records on their app database (but wouldn't surprise me either hehe)

suhtai avatar Jun 08 '18 17:06 suhtai

I was also contemplating creating a toSequence(Cursor.() -> T) : Sequence<T> which would may make it easier to use. But I'm not sure if it's out of the scope of ktx as it's kind of a new feature.

suhtai avatar Jun 08 '18 17:06 suhtai