Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Add empty check functions #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

pablisco
Copy link

@pablisco pablisco commented Jun 8, 2018

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
}

@JakeWharton
Copy link
Contributor

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.

@pablisco
Copy link
Author

pablisco commented Jun 8, 2018

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)

@pablisco
Copy link
Author

pablisco commented Jun 8, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants