#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Either { A(A), B(B), } impl Either { pub fn either(self, f1: F1, f2: F2) -> R where F1: FnOnce(A) -> R, F2: FnOnce(B) -> R, { match self { Either::A(a) => f1(a), Either::B(b) => f2(b), } } pub fn map(self, f1: F1, f2: F2) -> Either where F1: FnOnce(A) -> U, F2: FnOnce(B) -> V, { match self { Either::A(a) => Either::A(f1(a)), Either::B(b) => Either::B(f2(b)), } } }