1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4#[mel_function(
8 generic B (Binary)
9)]
10pub fn and(a: B, b: B) -> B {
11 a.binary_and(&b)
12}
13
14#[mel_treatment(
18 generic B (Binary)
19 input a Stream<B>
20 input b Stream<B>
21 output and Stream<B>
22)]
23pub async fn and() {
24 while let (Ok(a), Ok(b)) = (a.recv_one().await, b.recv_one().await) {
25 check!(and.send_one(a.binary_and(&b)).await)
26 }
27}
28
29#[mel_function(
33 generic B (Binary)
34)]
35pub fn or(a: B, b: B) -> B {
36 a.binary_or(&b)
37}
38
39#[mel_treatment(
43 generic B (Binary)
44 input a Stream<B>
45 input b Stream<B>
46 output or Stream<B>
47)]
48pub async fn or() {
49 while let (Ok(a), Ok(b)) = (a.recv_one().await, b.recv_one().await) {
50 check!(or.send_one(a.binary_or(&b)).await)
51 }
52}
53
54#[mel_function(
58 generic B (Binary)
59)]
60pub fn xor(a: B, b: B) -> B {
61 a.binary_xor(&b)
62}
63
64#[mel_treatment(
68 generic B (Binary)
69 input a Stream<B>
70 input b Stream<B>
71 output or Stream<B>
72)]
73pub async fn xor() {
74 while let (Ok(a), Ok(b)) = (a.recv_one().await, b.recv_one().await) {
75 check!(or.send_one(a.binary_xor(&b)).await)
76 }
77}
78
79#[mel_function(
83 generic B (Binary)
84)]
85pub fn not(value: B) -> B {
86 value.binary_not()
87}
88
89#[mel_treatment(
93 generic B (Binary)
94 input value Stream<B>
95 output not Stream<B>
96)]
97pub async fn not() {
98 while let Ok(values) = value
99 .recv_many()
100 .await
101 .map(|values| Into::<VecDeque<Value>>::into(values))
102 {
103 check!(
104 not.send_many(TransmissionValue::Other(
105 values.into_iter().map(|val| val.binary_not()).collect()
106 ))
107 .await
108 )
109 }
110}