From a4fc04ea865ff4f18304a56a3f9ffa9f04e34927 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Tue, 6 Jun 2017 13:18:31 -0700 Subject: [PATCH] Pre: Crib map_{left,right} for Either. --- db/src/internal_types.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/db/src/internal_types.rs b/db/src/internal_types.rs index 7b90978c..724a1cf4 100644 --- a/db/src/internal_types.rs +++ b/db/src/internal_types.rs @@ -39,6 +39,27 @@ pub enum Either { Right(R), } +// Cribbed from https://github.com/bluss/either/blob/f793721f3fdeb694f009e731b23a2858286bc0d6/src/lib.rs#L219-L259. +impl Either { + pub fn map_left(self, f: F) -> Either + where F: FnOnce(L) -> M + { + match self { + Left(l) => Left(f(l)), + Right(r) => Right(r), + } + } + + pub fn map_right(self, f: F) -> Either + where F: FnOnce(R) -> S + { + match self { + Left(l) => Left(l), + Right(r) => Right(f(r)), + } + } +} + use self::Either::*; pub type EntidOr = Either;