bluebird/
lib.rs

1use std::cmp;
2
3#[allow(unused_macros)]
4#[macro_export]
5macro_rules! phi1 {
6    ($a:expr, $b:expr, $c:expr) => {{
7        |x: i32, y: i32| {
8            let a = $a;
9            let b = $b;
10            let c = $c;
11            b(a(x, y), c(x, y))
12        }
13    }};
14}
15
16#[allow(dead_code)]
17type BinOp = fn(i32, i32) -> i32;
18
19nofmt::pls! {
20
21    pub const _MAX_:  BinOp    = |x: i32, y: i32| cmp::max(x, y);
22    pub const _MIN_:  BinOp    = |x: i32, y: i32| cmp::min(x, y);
23    pub const _MUL_:  BinOp    = |x: i32, y: i32| x * y;
24    pub const _PLUS_: BinOp    = |x: i32, y: i32| x + y;
25    pub const _L_:    BinOp    = |x: i32, _: i32| x;
26    pub const _R_:    BinOp    = |_: i32, y: i32| y;
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn phi1_test() {
35        assert_eq!(phi1!(_MAX_, _PLUS_, _R_)(3, 2), 5);
36        assert_eq!(phi1!(_R_, _MUL_, _R_)(3, 2), 4);
37        assert_eq!(phi1!(_L_, _MUL_, _PLUS_)(3, 2), 15);
38        assert_eq!(phi1!(_MUL_, _MIN_, _PLUS_)(3, 2), 5);
39    }
40}