zendesk / android-db-commons

Some common utilities for ContentProvider/ContentResolver/Cursor and other db-related android stuff
Apache License 2.0
222 stars 28 forks source link

FluentCursor.toFirstRow() - no differerence between missing row and row transformed to the null value #20

Closed chalup closed 10 years ago

chalup commented 10 years ago

The idea was good enough for my original use case, but I'm getting second thoughts about this now. Since Guava's Optional cannot contain null value, I see few options:

  1. Return nullable T (not Optional) and throw an exception when such transform is used on the empty cursor.
  2. Forbid returning null from transforming Function.
  3. Return some other wrapper over T which accepts null values.

Let me know what do you think about this.

chalup commented 10 years ago

Yet another idea:

  1. Return FluentIterable containing zero or one row.

On the other hand, if you intend to get only one row, shouldn't you reather use LIMIT 1 for your query in the first place?