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
//! Splitter pattern: derives multiple logical messages from a single inbound `Exchange`.
//!
//! Implements the Enterprise Integration Pattern (EIP) "Splitter". A splitter breaks a
//! composite or aggregate message (e.g. a delimited string, a JSON array, a batch) into
//! multiple individual messages. In this minimal implementation the provided closure
//! returns a `Vec<Message>` representing the split parts.
//!
//! # Current Behavior & Limitation
//! The splitter invokes the user-supplied closure and, if the returned vector is non-empty,
//! stores ONLY the first resulting message in `exchange.out_msg`. The rest are discarded.
//! This is intentionally minimal for now. Future versions may:
//! * Emit all parts downstream via a `Vec<Message>` property.
//! * Produce cloned `Exchange`s for each part.
//! * Integrate with a downstream `RecipientList` or `Aggregator` automatically.
//!
//! # Use Cases
//! * Taking a CSV line and extracting the first column for downstream processing.
//! * Extracting primary record from a batch for quick validation.
//! * Demonstration / scaffolding before implementing full fan-out semantics.
//!
//! # Example (tokenizing text payload)
//! ```rust
//! use allora_core::{patterns::splitter::Splitter, route::Route, Exchange, Message};
//! let splitter = Splitter::new(|exchange: &Exchange| {
//! exchange.in_msg.body_text()
//! .map(|t| t.split_whitespace().map(Message::from_text).collect())
//! .unwrap_or_else(Vec::new)
//! });
//! let route = Route::new().add(splitter).build();
//! let mut exchange = Exchange::new(Message::from_text("one two three"));
//! let rt = tokio::runtime::Runtime::new().unwrap();
//! rt.block_on(async { route.run(&mut exchange).await.unwrap(); });
//! assert_eq!(exchange.out_msg.unwrap().body_text(), Some("one"));
//! ```
//!
//! # Edge Cases
//! * Empty returned vector => `out_msg` remains unchanged (None if unset).
//! * Mixed payload types allowed; only first message used when non-empty.
//! * Closure should be pure / side-effect free aside from constructing messages.
//!
//! # Testing Strategies
//! * Verify first-element extraction from multiple tokens.
//! * Ensure no `out_msg` when closure returns empty slice.
//! * Provide heterogeneous messages and confirm only first selected.
use crate::;
use ;
+ Send + Sync + 'static,