aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/either.rs
blob: 6714529d9d21592933b381122ea2d1e15010c253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Either<A, B> {
    A(A),
    B(B),
}

impl<A, B> Either<A, B> {
    pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V>
    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)),
        }
    }
}