https://kotlinlang.org logo
#flow
Title
# flow
v

Victor Collod

04/15/2022, 2:53 PM
Hello! Is there a way to wait for an update on a list of flows to generate another flow? for example, these could be stateflows of integers, one per resource, and I'd like to generate a flow which is the resource associated with the current maximum integer
w

wasyl

04/15/2022, 6:25 PM
Something like this?
Copy code
fun foo(
    ints1: Flow<Int>,
    ints2: Flow<Int>,
    ints3: Flow<Int>,
) = combine(ints1, ints2, ints3) { ints -> ints.maxOf { it } }
    .distinctUntilChanged()
    .flatMapLatest { currentMax -> getResource(currentMax) }

fun getResource(int: Int): Flow<String> = TODO()
v

Victor Collod

04/19/2022, 7:40 AM
sort of yes, except its a stateflow and you cannot get the associated resource from the maximum alone, but I think your answer helps out, thanks 🙂
thanks !
4 Views