Skip to content

Instantly share code, notes, and snippets.

@raulh82vlc
Last active June 10, 2020 08:21
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 raulh82vlc/b860c2ea8ba67c4c220098a0b7adba6b to your computer and use it in GitHub Desktop.
Save raulh82vlc/b860c2ea8ba67c4c220098a0b7adba6b to your computer and use it in GitHub Desktop.
flow builder and transforming into an Observable
@ExperimentalCoroutinesApi
override fun search(token: String, query: String)
: Observable<Either<Throwable, List<TweetApiModel>>>
= flow<Either<Throwable, List<TweetApiModel>>> {
val response = twitterApi.search(
requestsIOHandler.getTokenFormatted(token), query)
if (requestsIOHandler.searchIsSuccessful(response)) {
val tweets = requestsIOHandler.getTweets(response)
emit(Either.right(tweets))
} else {
emit(Either.left(EmptyResponseException()))
}
}.flowOn(taskThreading.ioDispatcher())
.asObservable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment