0

I'm looking to make a sample project with a clean architecture approach and i have some difficulties to transform a single to another.

I have my retrofit service (with a Single) :

@GET("nearbysearch/json") fun getNearbyPlaces(@Query("type") type: String, @Query("location") location: String, @Query("radius") radius: Int): Single<GooglePlacesNearbySearchResult>

And i use it in my repository implementation :

override fun getNearbyPlaces(type: String, location: String, radius: Int): Single<List<Place>> {
    return googlePlacesApi.getNearbyPlaces(type, location, radius)
        .subscribeOn(Schedulers.io())
        .observeOn(Schedulers.computation())
        .doOnSuccess { googlePlacesNearbySearchResult -> nearbyPlaceListResultMapper.transform(googlePlacesNearbySearchResult) }
}

In this single, i want to transform my Single<GooglePlacesNearbyResultSearch> to a Single<List<Place>>, and i want to do this with my mapper NearbyPlaceListResultMapper

The issue is i don't succeed in having a Single<List<Place>> at the end. I can transform it to an Observable or a Completable but not the Single one.

Can anyone help me to have it in a cleaner way ?

Thanks

JohnDot
  • 119
  • 1
  • 1
  • 2

1 Answers1

0

Assuming nearbyPlaceListResultMapper.transform returns the type List<Place>> you can use the map operation.

fun getNearbyPlaces(type: String, location: String, radius: Int): Single<List<Place>> {
    return googlePlacesApi.getNearbyPlaces(type, location, radius)
        .subscribeOn(Schedulers.io())
        .map { nearbyPlaceListResultMapper.transform(it) }
        .observeOn(Schedulers.computation())
}
Chris
  • 2,332
  • 1
  • 14
  • 17