Skip to content

Commit 11b1693

Browse files
committed
Add partial stream casting functions for handling NoVal and Deferred values
1 parent 1ed1fbe commit 11b1693

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/core/stream_casting.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{OutputStream, Value, core::StreamData};
1+
use crate::{
2+
OutputStream, Value, core::StreamData, lang::dynamic_lola::type_checker::PartialStreamValue,
3+
};
24
use futures::StreamExt;
35
use std::fmt::Debug;
46

@@ -23,3 +25,23 @@ pub fn from_typed_stream<T: Into<Value> + StreamData>(
2325
) -> OutputStream<Value> {
2426
Box::pin(stream.map(|x| x.into()))
2527
}
28+
29+
pub fn to_typed_partial_stream<T: TryFrom<Value, Error = ()> + Debug>(
30+
stream: OutputStream<Value>,
31+
) -> OutputStream<PartialStreamValue<T>> {
32+
Box::pin(stream.map(|x| match x {
33+
Value::NoVal => PartialStreamValue::NoVal,
34+
Value::Deferred => PartialStreamValue::Deferred,
35+
x => PartialStreamValue::Known(x.try_into().expect("Type error when casting stream")),
36+
}))
37+
}
38+
39+
pub fn from_typed_partial_stream<T: Into<Value> + StreamData>(
40+
stream: OutputStream<PartialStreamValue<T>>,
41+
) -> OutputStream<Value> {
42+
Box::pin(stream.map(|x| match x {
43+
PartialStreamValue::NoVal => Value::NoVal,
44+
PartialStreamValue::Deferred => Value::Deferred,
45+
PartialStreamValue::Known(value) => value.into(),
46+
}))
47+
}

0 commit comments

Comments
 (0)