althaf
10/11/2022, 5:07 AMoverride suspend fun load(params: LoadParams<Int>): LoadResult<Int, Hotel> {
val currentPage = params.key ?: pageSetting.page
hotelSearchRepository.search(
hotelInquiry,
page = currentPage,
itemsPerPage = pageSetting.records
).collect { result ->
>>>>> return@collect result.fold(onSuccess = { hotelInquiryDetails ->
Page(
data = hotelInquiryDetails.hotels,
prevKey = if (currentPage == STARTING_PAGE_INDEX) null else (currentPage - 1),
nextKey = if (hotelInquiryDetails.hotels.isEmpty()) null else (currentPage + pageSetting.records)
)
}, onFailure = {
Error<Int, Hotel>(Exception(it))
})
}
} <<<<< - Error not return statement
gildor
10/11/2022, 5:31 AMgildor
10/11/2022, 5:32 AMval result = hotelSearchRepository.search(...).first()
gildor
10/11/2022, 5:32 AMgildor
10/11/2022, 5:33 AMgildor
10/11/2022, 5:42 AMalthaf
10/11/2022, 5:49 AMgildor
10/11/2022, 6:04 AMflow it self has soo much subtle points to to be kept in mindWell, yes, flow is abstraction for Reactive Streams, not only kotlin flow, it’s very similar to RxJava, Reactor etc So if you have stream of data/events it’s perfect abstraction for it, but encoding one time-events is not the best, it adds too much complexity and I would recommend to use suspend functions as soon as it enough for your use case