Commit 33bca14f authored by Klaus Aehlig's avatar Klaus Aehlig

Generalize mkResultT to arbitrary showable failures

A lot of Ganeti function return a type IO (GenericResult e a)
with various failure types e. It is often necessary to combine
all those results in a generic ResultT String IO a
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 77134c1e
......@@ -42,6 +42,7 @@ module Ganeti.BasicTypes
, Result
, ResultT(..)
, mkResultT
, mkResultT'
, withError
, withErrorT
, toError
......@@ -292,6 +293,11 @@ tryError = flip catchError (return . Left) . liftM Right
mkResultT :: (Monad m, Error e) => m (Result a) -> ResultT e m a
mkResultT = ResultT . liftM toErrorStr
-- | Generalisation of mkResultT accepting any showable failures.
mkResultT' :: (Monad m, Error e, Show s)
=> m (GenericResult s a) -> ResultT e m a
mkResultT' = mkResultT . liftM (genericResult (Bad . show) Ok)
-- | Simple checker for whether a 'GenericResult' is OK.
isOk :: GenericResult a b -> Bool
isOk (Ok _) = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment