1pub use qualified_do_macro::qdo;
2
3pub mod iter;
4pub use iter::Iter;
5pub use iter::ZipIter;
6
7pub use functo_rs::control::AsControl;
8pub use functo_rs::data::AsData;
9pub use functo_rs::impls::*;
10pub use functo_rs::nonlinear::AsNonlinear;
11
12pub type Optioned = AsControl<OptionFunctor>;
13pub type Resulted<E> = AsControl<ResultFunctor<E>>;
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18 #[test]
19 fn test_optioned_applicative() {
20 let answer = qdo! {Optioned {
21 x <- Some(1);
22 y <- Some(2);
23 return x + y + 100
24 }};
25 assert_eq!(answer, Some(103));
26 }
27
28 #[test]
29 fn text_optioned_resulted_nested() {
30 #[derive(Debug, Copy, Clone)]
31 enum Go {
32 Go,
33 NoGo,
34 }
35 let ans: fn(Go) -> Result<i64, String> = |go: Go| {
36 qdo! { Resulted {
37 x <- qdo!{ Optioned {
38 x <- Some(1);
39 y <- Some(2);
40 Go::Go <- Some(go);
41 guard x + y % 2 == 1;
42 return x + y + 100
43 }}.ok_or("Failed".to_string());
44 y <- Ok(3);
45 return x + y + 1000
46 }}
47 };
48 assert_eq!(ans(Go::Go), Ok(1106));
49 assert_eq!(ans(Go::NoGo), Err("Failed".to_string()));
50 }
51}