std_mel/ops/vec/
mod.rs

1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4pub mod block;
5
6#[mel_function(
7    generic T (PartialEquality)
8)]
9pub fn contains(vector: Vec<T>, value: T) -> bool {
10    vector.iter().any(|val| val.partial_equality_eq(&value))
11}
12
13#[mel_treatment(
14    generic T (PartialEquality)
15    input value Stream<T>
16    input vec Stream<Vec<T>>
17    output contains Stream<bool>
18)]
19pub async fn contains() {
20    while let (Ok(value), Ok(Value::Vec(vec))) = (value.recv_one().await, vec.recv_one().await) {
21        check!(
22            contains
23                .send_one(vec.iter().any(|val| val.partial_equality_eq(&value)).into())
24                .await
25        )
26    }
27}
28
29#[mel_function(
30    generic T ()
31)]
32pub fn concat(mut first: Vec<T>, mut second: Vec<T>) -> Vec<T> {
33    first.append(&mut second);
34    first
35}
36
37#[mel_treatment(
38    generic T ()
39    input first Stream<Vec<T>>
40    input second Stream<Vec<T>>
41    output concatened Stream<Vec<T>>
42)]
43pub async fn concat() {
44    while let (Ok(Value::Vec(mut first)), Ok(Value::Vec(mut second))) =
45        (first.recv_one().await, second.recv_one().await)
46    {
47        first.append(&mut second);
48        check!(concatened.send_one(Value::Vec(first)).await)
49    }
50}