Open
Description
If one wants to combine a list of streams that may be also empty or only contains one stream, the solution would be to do this over and over:
final streams = <Stream>[...];
if (streams.isEmpty) {
return Stream.value(<T>[]);
}
if (streams.length == 1) {
return streams[0].map<List<T>>((event) => <T>[event]);
}
return streams[0].combineLatestAll(streams.sublist(1));
This is not very clean to write over and over and seems to me like a pretty common use-case especially if you deal with server data collections.
I would propose to add a function like this to stream transform natively:
Stream<List<T>> combineStreams<T>(List<Stream<T>> streams) {
if (streams.isEmpty) {
return Stream.value(<T>[]);
}
if (streams.length == 1) {
return streams[0].map<List<T>>((event) => <T>[event]);
}
return streams[0].combineLatestAll(streams.sublist(1));
}