diff options
Diffstat (limited to 'crates/ra_hir/src/either.rs')
-rw-r--r-- | crates/ra_hir/src/either.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs index 6714529d9..4073cc82e 100644 --- a/crates/ra_hir/src/either.rs +++ b/crates/ra_hir/src/either.rs | |||
@@ -5,6 +5,16 @@ pub enum Either<A, B> { | |||
5 | } | 5 | } |
6 | 6 | ||
7 | impl<A, B> Either<A, B> { | 7 | impl<A, B> Either<A, B> { |
8 | pub fn either<R, F1, F2>(self, f1: F1, f2: F2) -> R | ||
9 | where | ||
10 | F1: FnOnce(A) -> R, | ||
11 | F2: FnOnce(B) -> R, | ||
12 | { | ||
13 | match self { | ||
14 | Either::A(a) => f1(a), | ||
15 | Either::B(b) => f2(b), | ||
16 | } | ||
17 | } | ||
8 | pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V> | 18 | pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V> |
9 | where | 19 | where |
10 | F1: FnOnce(A) -> U, | 20 | F1: FnOnce(A) -> U, |