Abhimanyu
06/14/2024, 9:57 AMcombine (flow1, flow2, flow3, ...) { data1, data2, data3, ... ->
DataStructure(data1, data2, data3, ...) // DataStructure would be Pair(), Triple, etc depending on number of flows
}.collectLatest { (data1, data2, data3, ...) ->
// Can use all data in type safe way
}
As the above code requires DataStructure
to be modified for any flow addition or removal from the combine
, and also to create new custom DataStructure
for more than 3 data.
How can I change this in a type safe way?
combine (flow1, flow2, flow3, ...) { dataList ->
dataList
}.collectLatest { dataList ->
// Can NOT use all data in type safe way, the data type is Array<Any?>
}
This code loses the type safety as the data list is Array<Any?>
.Stylianos Gakis
06/14/2024, 10:15 AMAbhimanyu
06/14/2024, 10:15 AMDataStructure
classes and it is lot of boiler plate code.Abhimanyu
06/14/2024, 10:16 AMthe above code requiresto be modified for any flow addition or removal from theDataStructure
combine
Stylianos Gakis
06/14/2024, 10:21 AMcombineLatest
function, or rather 12 functions or however many parameters you want to combine, which will internally do a combine, create that 1-12 parameter instance, and then pass the items individually inside the lambda.Abhimanyu
06/14/2024, 10:23 AMStylianos Gakis
06/14/2024, 10:23 AMStylianos Gakis
06/14/2024, 10:23 AMSo, there is no out of the box solutionNo AFAIK
Abhimanyu
06/14/2024, 10:23 AM