change_stream 0.1.0

A Stream that only emits if the value is different.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use change_stream::StreamChanged;
use futures::{stream::iter, StreamExt};
use multi_stream::multi_stream;

#[tokio::main]
async fn main() {
    let a = iter([1, 1, 2]);
    let b = iter([5, 5, 4]);

    //values are only emitted when their differ
    multi_stream!(a.changed(), b.changed())
        .map(|(a, b)| a.unwrap_or_default() + b.unwrap_or_default())
        .changed()
        .for_each(|c| async move {
            dbg!(c); //this is only called where the sum has also changed
        })
        .await;
}