module Data.Either.Extra where
mapEither :: (a -> b1) -> (b -> b2) -> Either a b -> Either b1 b2
mapEither l r = either (Left . l) (Right . r)
leftToMaybe :: Either a b -> Maybe a
leftToMaybe = either Just (const Nothing)
rightToMaybe :: Either a b -> Maybe b
rightToMaybe = either (const Nothing) Just
isLeft :: Either a b -> Bool
isLeft (Left _) = True
isLeft (Right _) = False
isRight :: Either a b -> Bool
isRight (Left _) = False
isRight (Right _) = True
fromLeft :: a -> Either a b -> a
fromLeft _ (Left x) = x
fromLeft x _ = x
fromRight :: b -> Either a b -> b
fromRight _ (Right x) = x
fromRight x _ = x
whenRight :: Monad m => Either a b -> (b -> m c) -> m ()
whenRight (Right x) m = m x >> return ()
whenRight _ _ = return ()
whenLeft :: Monad m => Either a b -> (a -> m c) -> m ()
whenLeft (Left x) m = m x >> return ()
whenLeft _ _ = return ()