0

I am using RxJava3 in my project and I can't write a request, I've been wrestling my head for several hours.

I have List<Stream> and have a function that returns a Single<List<Topic>> by Stream, i want to get a Single<Map<Stream, List<Topic>>>,

fun getMockTopics(streamId: Long): Single<List<Topic>> {
        return Single.just(listOf(Topic(1, "")))
    }
typealias SteamTopics = Map<Stream, List<Topic>>

override fun getTopics(streams: List<Stream?>): Single<SteamTopics> {
        return Observable.fromCallable { streams.filterNotNull() }.flatMapIterable { it }
            .map { stream ->
                Pair(stream, getMockTopics(streamId = stream.streamId))
            }.flatMap {
                TODO("???")
            }
            .toMap({ it.first }, { it.second })
    }
  • this isn't java, it's kotlin that you're having problems with? please tag the question appropriately – eis Apr 03 '21 at 09:01

1 Answers1

0
fun getMockTopics(streamId: Long): Observable<List<Topic>> {
    return Observable.just(listOf(Topic(1, "")))
}

override fun getTopics(streams: List<Stream?>): Single<SteamTopics> {
    return Observable.fromCallable { streams.filterNotNull() }.flatMapIterable { it }
        .flatMap({ stream ->
            getMockTopics(streamId = stream.streamId)
        }, { stream, topics ->
            Pair(stream, topics)
        }).toMap({ it.first }, { it.second })
}