Skip to main content

std_mel/ops/vec/
block.rs

1use melodium_core::*;
2use melodium_macro::mel_treatment;
3
4/// Check whether `vec` contains a value equal to `value` and emit the boolean result through `contains`.
5#[mel_treatment(
6    generic T (PartialEquality)
7    input value Block<T>
8    input vec Block<Vec<T>>
9    output contains Block<bool>
10)]
11pub async fn contains() {
12    if let (Ok(value), Ok(vec_value)) = (value.recv_one().await, vec.recv_one().await) {
13        let vec = match vec_value {
14            Value::Vec(vec) => vec,
15            Value::Packed(arr) => arr.into_values(),
16            _ => return,
17        };
18        let _ = contains
19            .send_one_as(vec.iter().any(|val| val.partial_equality_eq(&value)))
20            .await;
21    }
22}
23
24/// Append the elements of `second` to `first` and emit the combined vector through `concatened`.
25#[mel_treatment(
26    generic T ()
27    input first Block<Vec<T>>
28    input second Block<Vec<T>>
29    output concatened Block<Vec<T>>
30)]
31pub async fn concat() {
32    if let (Ok(first_value), Ok(second_value)) = (first.recv_one().await, second.recv_one().await) {
33        let mut first = match first_value {
34            Value::Vec(vec) => vec,
35            Value::Packed(arr) => arr.into_values(),
36            _ => return,
37        };
38        let mut second = match second_value {
39            Value::Vec(vec) => vec,
40            Value::Packed(arr) => arr.into_values(),
41            _ => return,
42        };
43        first.append(&mut second);
44        let _ = concatened.send_one_as(first).await;
45    }
46}