I have 2 Firestore streams where the 2nd one depends on the 1st one. I want to emit new models that depend on data from both streams.
In pseudocode you can think of it in a following way:
// 1st stream emits some device data
final streamA = client.device(id: 0); // Stream<DeviceData>
// 2nd stream emits some metadata for the above device type
final streamB = client.deviceMetadata(type: device.type); // Stream<DeviceMetadata>
// and finally I want to receive stream of combined device (device data + metadata)
final combinedObject = Device.from(deviceData, deviceMetadata);
However, I cannot find an effective way of mapping a stream onto another stream while accessing the value from the source stream. For instance with .map() I would like to write:
return client.device('deviceId')
.map((device) => client.deviceMetadata(type: device.type))
.map((deviceMetadata) => Device.from(???, deviceMetadata));
The problem is of course that I don't know how to access device in the second map().
What stream transformation or rxdart extension I could use to achieve that?