Skip to content

Instantly share code, notes, and snippets.

@kcrimi
Last active April 30, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcrimi/4e39a7ab492d96859870e37abbbc76ce to your computer and use it in GitHub Desktop.
Save kcrimi/4e39a7ab492d96859870e37abbbc76ce to your computer and use it in GitHub Desktop.
Maybe to single
fun MaybeToSingle() : Single<DownloadStatus> {
return getDownloadQueueItem(videoId) // Maybe<DownloadQueueItem>
.map { it.getDownloadServiceStatus() } // Single<Single<DownloadStatus>>
.switchIfEmpty( Single.just(Single.just(NOT_DOWNLOADING)) ) // Single<Single<DownloadStatus>>
.flatMap { it }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment