From 8cfa9e3cb0c76d91ee4616e3f9bee3e31be63992 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 15 Jan 2008 17:05:45 +0000 Subject: [PATCH] Added a new helper function to Utils (transformTriple) --- common/Utils.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/Utils.hs b/common/Utils.hs index ce42451..d6ba900 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -76,8 +76,9 @@ splitEither ((Right y):es) = let (ls,rs) = splitEither es in (ls,y:rs) -- | Transforms between two 'Maybe' types using a function: transformMaybe :: (a -> b) -> Maybe a -> Maybe b -transformMaybe _ Nothing = Nothing -transformMaybe f (Just x) = Just (f x) +--transformMaybe _ Nothing = Nothing +--transformMaybe f (Just x) = Just (f x) +transformMaybe = liftM -- | Try an IO operation, returning `Nothing` if it fails. maybeIO :: IO a -> IO (Maybe a) @@ -118,6 +119,10 @@ combineCompare (EQ:os) = combineCompare os transformPair :: (x -> a) -> (y -> b) -> (x,y) -> (a,b) transformPair f g (x,y) = (f x, g y) +-- | Maps two functions over members of a triple +transformTriple :: (x -> a) -> (y -> b) -> (z -> c) -> (x,y,z) -> (a,b,c) +transformTriple f g h (x,y,z) = (f x, g y, h z) + -- | Pipes a monadic return through a non-monadic transformation function: (>>*) :: Monad m => m a -> (a -> b) -> m b (>>*) v f = v >>= (return . f)