Add Stream support for field accessors
The type checker now correctly handles unwrapping `Stream(T)` types for lambda arguments. A new `build_map_stream` function has been added to `rtl/streams.rs` to facilitate field access on streams. The `create-random-ohlc` function now returns a `Stream` instead of a `Series`. Examples have been updated to reflect these changes and demonstrate stream usage.
This commit is contained in:
+29
-1
@@ -416,6 +416,34 @@ pub fn build_pipeline_node(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_map_stream(input: Rc<dyn ObservableStream>, field: Keyword) -> StreamNode {
|
||||
let executor: Box<PipeFn> = Box::new(move |args: &[Value]| -> Value {
|
||||
let val = &args[0];
|
||||
if let Value::Record(layout, values) = val
|
||||
&& let Some(idx) = layout.index_of(field)
|
||||
{
|
||||
return values[idx].clone();
|
||||
}
|
||||
Value::Void // In streams, Void acts as a filter
|
||||
});
|
||||
|
||||
let pipe = Rc::new(RefCell::new(PipeStream::new(
|
||||
format!("map:{}", field.name()),
|
||||
1,
|
||||
Some(executor),
|
||||
)));
|
||||
|
||||
let adapter = Rc::new(RefCell::new(SourceAdapter {
|
||||
target: pipe.clone(),
|
||||
target_index: 0,
|
||||
}));
|
||||
input.add_observer(adapter);
|
||||
|
||||
StreamNode {
|
||||
inner: pipe,
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Script Integration (RTL Registration)
|
||||
// ============================================================================
|
||||
@@ -439,7 +467,7 @@ pub fn register(env: &Environment) {
|
||||
"create-random-ohlc",
|
||||
StaticType::Function(Box::new(Signature {
|
||||
params: StaticType::Tuple(vec![StaticType::Int, StaticType::Int]),
|
||||
ret: StaticType::Series(Box::new(StaticType::Record(ohlc_layout.clone()))),
|
||||
ret: StaticType::Stream(Box::new(StaticType::Record(ohlc_layout.clone()))),
|
||||
})),
|
||||
Purity::Impure, // Modifies global generator registry
|
||||
move |args: &[Value]| {
|
||||
|
||||
Reference in New Issue
Block a user