Guest User

Untitled

a guest
Nov 25th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. inline fun <T : Any> ContentResolver.itemsFor(
  2. crossinline queryRawData: ContentResolver.() -> Cursor,
  3. crossinline mapRawData: (Cursor) -> T): Flowable<T> =
  4. Flowable.generate<T, Cursor>(
  5. Callable<Cursor> { queryRawData(this) },
  6. BiFunction<Cursor, Emitter<T>, Cursor> { cursor, emitter ->
  7. if (cursor.moveToNext()) {
  8. emitter.onNext(mapRawData(cursor))
  9. } else {
  10. emitter.onComplete()
  11. }
  12. return@BiFunction cursor
  13. },
  14. Consumer<Cursor> { cursor -> cursor.close() }
  15. )
Add Comment
Please, Sign In to add comment