我正在寻找一个具有干净架构方法的样本项目,我在将一个项目转换为另一个项目时有一些困难。
我有我的翻新服务(只有一个):
@GET("nearbysearch/json") fun getNearbyPlaces(@Query("type") type: String, @Query("location") location: String, @Query("radius") radius: Int): Single<GooglePlacesNearbySearchResult>我在我的存储库实现中使用了它:
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) }
}在本示例中,我希望将Single<GooglePlacesNearbyResultSearch>转换为Single<List<Place>>,并使用映射器NearbyPlaceListResultMapper完成此操作
问题是我最终没有成功地拥有一个Single<List<Place>>。我可以将其转换为可观察的或可完成的,但不是单一的。
有没有人能帮我把它弄得更干净?
谢谢
发布于 2018-09-11 01:56:23
假设nearbyPlaceListResultMapper.transform返回类型List<Place>>,您可以使用map操作。
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())
}https://stackoverflow.com/questions/52255995
复制相似问题