Is there a function that splits a `Flow<Unmappe...
# flow
m
Is there a function that splits a
Flow<UnmappedValue>
into a
Map<SomeKey, Flow<MappedValue>>
? Like the opposite of
merge
? Maybe
explode
or
subFlows
or something like that?
w
Not sure how that would work - you’d want to have a
Flow
continuously add to a mutable map?
m
I figured it out and made a function, basically I needed this
Copy code
fun <Key, Input, Result> Flow<Input>.toMapOfFlowsBy(mapping: Map<Key, (Key, Input) -> Result>): Map<Key, Flow<Result>> =
    mapping.mapValues { (key, transform) -> map { transform(key, it) } }
You could also do the same thing with a
List
if you wanted
👍 1