I'm converting some Java code to Kotlin and I'm having some trouble with flattenAsObservable()
Here's what the code looked like in Java:
discogsInteractor.search(query)
.map(RootSearchResponse::getSearchResults)
.flattenAsObservable(searchResults -> searchResults)
.take(12)
Here's what I have so far in Kotlin:
discogsInteractor.search(query)
.map { RootSearchResponse::searchResults }
.flattenAsObservable<SearchResult> { searchResults -> searchResults }
.take(12)
It underlines the second searchResults
and gives me the following error:
Required: (Mutable)Iterable<SearchResult!>!
Found: KProperty1<RootSearchResponse, List<SearchResult>>!
I can replace
.map { RootSearchResponse::searchResults }
with
.map { searchResponse -> searchResponse.searchResults }
and it will work. How do I correctly method reference? Or what's the reason that I can't in this instance?
RootSearchResponse:
data class RootSearchResponse(val pagination: Pagination,
@SerializedName("results") val searchResults: List<SearchResult>)