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(Value::Vec(vec))) = (value.recv_one().await, vec.recv_one().await) {
13        let _ = contains
14            .send_one(vec.iter().any(|val| val.partial_equality_eq(&value)).into())
15            .await;
16    }
17}
18
19/// Append the elements of `second` to `first` and emit the combined vector through `concatened`.
20#[mel_treatment(
21    generic T ()
22    input first Block<Vec<T>>
23    input second Block<Vec<T>>
24    output concatened Block<Vec<T>>
25)]
26pub async fn concat() {
27    if let (Ok(Value::Vec(mut first)), Ok(Value::Vec(mut second))) =
28        (first.recv_one().await, second.recv_one().await)
29    {
30        first.append(&mut second);
31        let _ = concatened.send_one(Value::Vec(first)).await;
32    }
33}