dfir_lang/graph/ops/
chain.rs

1use crate::graph::PortIndexValue;
2
3use super::{
4    DelayType, OperatorCategory, OperatorConstraints, RANGE_0, RANGE_1
5};
6
7/// > 2 input streams of the same type, 1 output stream of the same type
8///
9/// Chains together a pair of streams, with all the elements of the first emitted before the second.
10///
11/// Since `chain` has multiple input streams, it needs to be assigned to
12/// a variable to reference its multiple input ports across statements.
13///
14/// ```dfir
15/// source_iter(vec!["hello", "world"]) -> [0]my_chain;
16/// source_iter(vec!["stay", "gold"]) -> [1]my_chain;
17/// my_chain = chain()
18///     -> map(|x| x.to_uppercase())
19///     -> assert_eq(["HELLO", "WORLD", "STAY", "GOLD"]);
20/// ```
21pub const CHAIN: OperatorConstraints = OperatorConstraints {
22    name: "chain",
23    categories: &[OperatorCategory::MultiIn],
24    persistence_args: RANGE_0,
25    type_args: RANGE_0,
26    hard_range_inn: &(2..=2),
27    soft_range_inn: &(2..=2),
28    hard_range_out: RANGE_1,
29    soft_range_out: RANGE_1,
30    num_args: 0,
31    is_external_input: false,
32    has_singleton_output: false,
33    flo_type: None,
34    ports_inn: None,
35    ports_out: None,
36    input_delaytype_fn: |idx| match idx {
37        PortIndexValue::Int(idx) if idx.value == 0 => {
38            Some(DelayType::Stratum)
39        }
40        _else => None,
41    },
42    write_fn: super::union::UNION.write_fn,
43};