Pre: Crib map_{left,right} for Either.
This commit is contained in:
parent
634b7a816b
commit
a4fc04ea86
1 changed files with 21 additions and 0 deletions
|
@ -39,6 +39,27 @@ pub enum Either<L, R> {
|
|||
Right(R),
|
||||
}
|
||||
|
||||
// Cribbed from https://github.com/bluss/either/blob/f793721f3fdeb694f009e731b23a2858286bc0d6/src/lib.rs#L219-L259.
|
||||
impl<L, R> Either<L, R> {
|
||||
pub fn map_left<F, M>(self, f: F) -> Either<M, R>
|
||||
where F: FnOnce(L) -> M
|
||||
{
|
||||
match self {
|
||||
Left(l) => Left(f(l)),
|
||||
Right(r) => Right(r),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_right<F, S>(self, f: F) -> Either<L, S>
|
||||
where F: FnOnce(R) -> S
|
||||
{
|
||||
match self {
|
||||
Left(l) => Left(l),
|
||||
Right(r) => Right(f(r)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use self::Either::*;
|
||||
|
||||
pub type EntidOr<T> = Either<Entid, T>;
|
||||
|
|
Loading…
Reference in a new issue