aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2015-02-18 21:05:47 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2015-02-18 21:09:07 +0000
commitad39bc7009e320b3afb91a5683521eb1eccf0ef7 (patch)
treec522e3cf44db35ef3ac39c9484133f9a790d0e95 /src/Text/Pandoc/Shared.hs
parent48f442f4770c774534b3696e6dd696da45395874 (diff)
downloadpandoc-ad39bc7009e320b3afb91a5683521eb1eccf0ef7.tar.gz
Move utility error functions to Text.Pandoc.Shared
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 90d0941c1..e0460c66e 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -85,6 +85,8 @@ module Text.Pandoc.Shared (
-- * Error handling
err,
warn,
+ mapLeft,
+ hush,
-- * Safe read
safeRead,
-- * Temp directory
@@ -855,6 +857,14 @@ warn msg = do
name <- getProgName
UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
+mapLeft :: (a -> b) -> Either a c -> Either b c
+mapLeft f (Left x) = Left (f x)
+mapLeft _ (Right x) = Right x
+
+hush :: Either a b -> Maybe b
+hush (Left _) = Nothing
+hush (Right x) = Just x
+
-- | Remove intermediate "." and ".." directories from a path.
--
-- > collapseFilePath "./foo" == "foo"