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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//! # hyphae - Lock-Free Reactive Programming Library
//!
//! A high-performance, type-safe reactive programming library featuring true lock-free operations,
//! heterogeneous cell combinations, and comprehensive dependency tracking.
//!
//! ## Features
//!
//! - **Lock-Free**: Uses `arc-swap` for atomic value updates without blocking
//! - **Type-Safe**: Full compile-time type checking with heterogeneous cell support
//! - **Automatic Propagation**: Changes flow through dependency chains automatically
//! - **Dependency Tracking**: Inspect and visualize cell relationships
//! - **Thread-Safe**: Safe concurrent access across threads
//!
//! ## Quick Start
//!
//! ```rust
//! use hyphae::{Cell, MapExt, MaterializeDefinite, Mutable, Watchable, JoinExt, Pipeline, Signal, flat};
//!
//! // Create reactive cells
//! let x = Cell::new(5).with_name("x");
//! let y = Cell::new(10).with_name("y");
//!
//! // Pure operators (map/filter/...) return pipelines — no allocation
//! // until you materialize.
//! let doubled = x.clone().map(|val| val * 2).materialize().with_name("doubled");
//!
//! // Combine multiple cells with join + flat!. join is stateful — it
//! // returns a Cell directly. Chaining .map fuses into the join's
//! // installed callback when materialized.
//! let sum = x.join(&y).map(flat!(|a, b| a + b)).materialize().with_name("sum");
//!
//! // Subscribe on the materialized cell
//! let _guard = sum.subscribe(|signal| {
//! if let Signal::Value(value) = signal {
//! println!("Sum changed to: {}", value);
//! }
//! });
//!
//! x.set(20); // Triggers updates
//! ```
//!
//! ## Pipelines vs Cells
//!
//! Pure operators (`map`, `filter`, `try_map`, `tap`, `map_ok`, `map_err`,
//! `catch_error`, `unwrap_or`) return a [`Pipeline`] — an uncompiled chain
//! that has not yet been materialized into a [`Cell`]. Chaining pipelines
//! fuses closures at compile time; the fused closure runs only when a
//! consumer calls [`Pipeline::materialize`].
//!
//! [`Cell`] is the materialized, cached, multicast form. Subscribing requires
//! a cell — there is no `Pipeline::subscribe` by design, forcing callers to
//! make the memoization decision explicit.
//!
//! Stateful operators (`scan`, `debounce`, `throttle`, `buffer_*`, `pairwise`,
//! `window`, `distinct*`, `sample`, `delay`, `take`, `first`, `last`, `merge`,
//! `merge_map`, `switch_map`, `with_latest_from`, `zip`, `join`) return cells
//! directly — they hold per-subscription state, so memoization is unavoidable.
//!
//! ## Combining Cells
//!
//! Use `join()` to combine cells, and the `flat!` macro to avoid nested tuple destructuring.
//! `join` is stateful and returns a [`Cell`] directly, so the chain below is a cell
//! once `.map(...)` fuses onto it — no `.materialize()` needed for `.get()`:
//!
//! ```rust
//! use hyphae::{Cell, Gettable, JoinExt, MapExt, MaterializeDefinite, flat};
//!
//! let a = Cell::new(1);
//! let b = Cell::new(2);
//! let c = Cell::new(3);
//! let d = Cell::new(4);
//!
//! // Without flat!: |(((a, b), c), d)| - deeply nested
//! // With flat!: |a, b, c, d| - clean and simple
//! let sum = a
//! .join(&b)
//! .join(&c)
//! .join(&d)
//! .map(flat!(|a, b, c, d| a + b + c + d))
//! .materialize();
//! assert_eq!(sum.get(), 10);
//! ```
//!
//! ## Map Queries vs CellMaps
//!
//! Pure [`CellMap`] operators (`inner_join`, `left_join`, `left_semi_join`,
//! `multi_left_join`, `project`, `project_many`, `project_cell`, `select`,
//! `select_cell`, `count_by`, `group_by`) return uncompiled [`MapQuery`]
//! plan nodes — not [`CellMap`]s. A plan tree composes freely: any plan or
//! [`CellMap`] can feed any other operator's input.
//!
//! Calling [`MapQuery::materialize`] allocates ONE output [`CellMap`] with
//! ONE subscription per root source running the fully fused diff-propagation
//! closure. This replaces what used to be N intermediate [`CellMap`]s, N
//! subscriber tables, and N `ArcSwap` chains for an N-stage query.
//!
//! [`MapQuery`] plan nodes are deliberately not `Clone` (mirroring
//! [`Pipeline`]). Cloning would silently duplicate join / projection work —
//! every clone's `materialize()` would install independent root subscriptions
//! and re-run the entire op chain. To share work across consumers,
//! materialize once into a [`CellMap`] (which IS `Clone` — the clone is an
//! `Arc` bump referencing the same multicast cache) and then clone the cell
//! map.
//!
//! ## CellMap Quick Start
//!
//! ```rust
//! use hyphae::{CellMap, MapQuery, traits::{InnerJoinExt, ProjectMapExt}};
//!
//! let users = CellMap::<String, &'static str>::new();
//! let scores = CellMap::<String, i32>::new();
//! users.insert("u1".into(), "alice");
//! scores.insert("u1".into(), 42);
//!
//! // Chained operators return plan nodes — no intermediate CellMap
//! // until materialize().
//! let view = users
//! .clone()
//! .inner_join(scores.clone())
//! .project(|user_id, (name, score)| Some((user_id.clone(), format!("{name}:{score}"))))
//! .materialize();
//!
//! assert!(view.contains_key(&"u1".to_string()));
//! ```
pub use ;
pub use ;
pub use BoundedOutput;
pub use SlowSubscriberAlert;
pub use ;
pub use ;
pub use ;
pub use from_iter_with_delay;
pub use ;
pub use ;
pub use CellMetrics;
pub use NestedMap;
pub use ;
pub use Signal;
pub use ;
pub use SubscriptionGuard;
pub use ;
pub use ;
pub use ;