1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
//! A stateful stream merger that combines multiple Timestamped streams while maintaining state.
//!
//! The `MergedStream` struct allows merging multiple streams into a single one, preserving
//! temporal order and allowing stateful processing of each item.
//!
//! # Example
//!
//! ```rust
//! use fluxion_stream::MergedStream;
//! use fluxion_test_utils::{Sequenced, helpers::unwrap_stream, unwrap_value, test_channel};
//! use futures::StreamExt;
//!
//! # async fn example() {
//! // Initial state is 0
//! let stream = MergedStream::seed::<Sequenced<i32>>(0);
//!
//! let (tx, rx) = test_channel::<Sequenced<i32>>();
//!
//! // Merge a stream that adds its value to the state and emits the new state
//! let mut stream = stream.merge_with(rx, |val, state| {
//! *state += val;
//! *state
//! });
//!
//! tx.unbounded_send((10, 1).into()).unwrap();
//! tx.unbounded_send((20, 2).into()).unwrap();
//!
//! let first = unwrap_value(Some(unwrap_stream(&mut stream, 500).await));
//! assert_eq!(first.value, 10); // 0 + 10
//!
//! let second = unwrap_value(Some(unwrap_stream(&mut stream, 500).await));
//! assert_eq!(second.value, 30); // 10 + 20
//! # }
//! ```
pub use MergedStream;
pub use MergedStream;