I have the following interface to fetch recipes
interface FoodService {
@GET(EndPoint.COMPLEX_SEARCH)
suspend fun fetchComplexSearch(@Query("apiKey") apiKey: String): ResultModel
}
This works find using a flow builder
override fun complexSearch(apiKey: String): Flow<List<ComplexSearchEntity>> {
return flow {
val resultModel = foodService.fetchComplexSearch(apiKey)
val listOfComplexSearchEntity = resultModel.results.map { complexSearchModel ->
mapperDataToDomain.map(complexSearchModel)
}
emit(listOfComplexSearchEntity)
}
}
However, I get an error when I use the extension asFlow
override fun complexSearch(apiKey: String): Flow<List<ComplexSearchEntity>> {
return foodService.fetchComplexSearch(apiKey).results.map {
mapperDataToDomain.map(it)
}.asFlow()
}
Error 1
Required:
Flow<List<ComplexSearchEntity>>
Found:
Flow<ComplexSearchEntity>
Error 2
Suspend function 'fetchComplexSearch' should be called only from a coroutine or another suspend function