1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4#[mel_function]
6pub fn equal(a: bool, b: bool) -> bool {
7 a == b
8}
9
10#[mel_function]
12pub fn not_equal(a: bool, b: bool) -> bool {
13 a != b
14}
15
16#[mel_treatment(
18 input a Stream<bool>
19 input b Stream<bool>
20 output result Stream<bool>
21)]
22pub async fn equal() {
23 while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
24 check!(result.send_one_bool(a == b).await)
25 }
26}
27
28#[mel_treatment(
30 input a Stream<bool>
31 input b Stream<bool>
32 output result Stream<bool>
33)]
34pub async fn not_equal() {
35 while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
36 check!(result.send_one_bool(a != b).await)
37 }
38}
39
40#[mel_function]
42pub fn and(a: bool, b: bool) -> bool {
43 a & b
44}
45
46#[mel_function]
48pub fn or(a: bool, b: bool) -> bool {
49 a | b
50}
51
52#[mel_function]
54pub fn xor(a: bool, b: bool) -> bool {
55 a ^ b
56}
57
58#[mel_function]
60pub fn not(val: bool) -> bool {
61 !val
62}
63
64#[mel_treatment(
66 input a Stream<bool>
67 input b Stream<bool>
68 output result Stream<bool>
69)]
70pub async fn and() {
71 while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
72 check!(result.send_one_bool(a & b).await)
73 }
74}
75
76#[mel_treatment(
78 input a Stream<bool>
79 input b Stream<bool>
80 output result Stream<bool>
81)]
82pub async fn or() {
83 while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
84 check!(result.send_one_bool(a | b).await)
85 }
86}
87
88#[mel_treatment(
90 input a Stream<bool>
91 input b Stream<bool>
92 output result Stream<bool>
93)]
94pub async fn xor() {
95 while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
96 check!(result.send_one_bool(a ^ b).await)
97 }
98}
99
100#[mel_treatment(
102 input value Stream<bool>
103 output not Stream<bool>
104)]
105pub async fn not() {
106 while let Ok(values) = value.recv_bool().await {
107 check!(
108 not.send_bool(values.into_iter().map(|v| !v).collect())
109 .await
110 )
111 }
112}