Combines two streams into a new stream which yields tuples with the latest values from each input stream. Inspired by Rx's combineLatest.
```rust use asyncstream::stream; use combinelatest::combine_latest;
fn combineweatherdatastreams(
temperature: impl Stream
combine_latest
won't yield its first tuple until both input streams have yielded a value. If you
need to get items as soon as the first is available, there is a combine_latest_optional
function
that yields (Option
As values come in over time on the temperature
and weather_notes
streams, combine_latest
and
combine_latest_optional
will yield values like so:
|time| temperature | weathernotes | combinelatest | combinelatestoptional | |----|--------------|----------------|-----------------------|-----------------------------------| | 0 | 25 | | | (Some(25), None) | | 1 | 26 | | | (Some(26), None) | | 2 | | Low visibility | (26, "Low visibility")| (Some(26), Some("Low visibility"))| | 3 | | Foggy | (26, "Foggy") | (Some(26), Some("Foggy")) | | 4 | 25 | | (25, "Foggy") | (Some(25), Some("Foggy")) |
Since the same input value might be returned several times in the output stream, the items that the input streams yield must implement Clone.