Added a new helper function to Utils (transformTriple)

This commit is contained in:
Neil Brown 2008-01-15 17:05:45 +00:00
parent 421cff1017
commit 8cfa9e3cb0

View File

@ -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)