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:
Michael Schimmel
2026-03-07 20:47:05 +01:00
parent 2023df2f62
commit f88992da61
6 changed files with 105 additions and 28 deletions
+20
View File
@@ -311,6 +311,7 @@ pub enum StaticType {
Optional(Box<StaticType>), // Represents T | Void (e.g. for filter pipes)
List(Box<StaticType>), // Legacy / Dynamic list
Series(Box<StaticType>), // Time series of a specific type
Stream(Box<StaticType>), // Reactive stream of a specific type
Tuple(Vec<StaticType>), // Heterogeneous fixed-size
Vector(Box<StaticType>, usize), // Homogeneous fixed-size
Matrix(Box<StaticType>, Vec<usize>), // Multi-dimensional homogeneous
@@ -337,6 +338,7 @@ impl fmt::Display for StaticType {
StaticType::Optional(inner) => write!(f, "optional({})", inner),
StaticType::List(inner) => write!(f, "list({})", inner),
StaticType::Series(inner) => write!(f, "series<{}>", inner),
StaticType::Stream(inner) => write!(f, "stream<{}>", inner),
StaticType::Tuple(elements) => {
write!(f, "[")?;
for (i, el) in elements.iter().enumerate() {
@@ -440,6 +442,10 @@ impl StaticType {
(StaticType::Series(inner_a), StaticType::Series(inner_b)) => {
inner_a.is_assignable_from(inner_b)
}
// Streams are assignable if their inner types are assignable
(StaticType::Stream(inner_a), StaticType::Stream(inner_b)) => {
inner_a.is_assignable_from(inner_b)
}
_ => false,
}
}
@@ -463,6 +469,20 @@ impl StaticType {
return Some(layout.fields[idx].1.clone());
}
}
StaticType::Series(inner) => {
if let StaticType::Record(layout) = inner.as_ref()
&& let Some(idx) = layout.index_of(*k)
{
return Some(StaticType::Series(Box::new(layout.fields[idx].1.clone())));
}
}
StaticType::Stream(inner) => {
if let StaticType::Record(layout) = inner.as_ref()
&& let Some(idx) = layout.index_of(*k)
{
return Some(StaticType::Stream(Box::new(layout.fields[idx].1.clone())));
}
}
StaticType::Any => return Some(StaticType::Any),
_ => {}
}