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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
//! Extension trait providing the `emit_when` operator for timestamped streams.
//!
//! This operator gates a source stream based on conditions from a filter stream,
//! emitting source values only when the combined state passes a predicate.
//!
//! # Behavior
//!
//! - Maintains latest value from both source and filter streams
//! - Evaluates predicate on `CombinedState` containing both values
//! - Emits source value when predicate returns `true`
//! - Both streams must emit at least once before any emission occurs
//! - Preserves temporal ordering of source stream
//!
//! # Examples
//!
//! ```rust
//! use fluxion_stream::EmitWhenExt;
//! use fluxion_test_utils::{Sequenced, helpers::unwrap_stream, unwrap_value, test_channel};
//! use fluxion_core::Timestamped as TimestampedTrait;
//!
//! # async fn example() {
//! // Create channels
//! let (tx_data, data_stream) = test_channel::<Sequenced<i32>>();
//! let (tx_enable, enable_stream) = test_channel::<Sequenced<i32>>();
//!
//! // Combine streams
//! let mut gated = data_stream.emit_when(
//! enable_stream,
//! |state| {
//! let values = state.values();
//! values[1] > 0 // Enable when value > 0
//! }
//! );
//!
//! // Send values
//! tx_enable.unbounded_send((1, 1).into()).unwrap(); // Enabled
//! tx_data.unbounded_send((42, 2).into()).unwrap();
//!
//! // Assert - data emits when enabled
//! let result = unwrap_value(Some(unwrap_stream(&mut gated, 500).await));
//! assert_eq!(result.value, 42);
//! # }
//! ```
//!
//! # Use Cases
//!
//! - Conditional forwarding based on external signals
//! - State-dependent filtering
//! - Complex gating logic involving multiple stream values
pub use EmitWhenExt;
pub use EmitWhenExt;