module Manatee.Toolkit.General.Basic where
import Control.Arrow
import Control.Monad hiding (filterM, mapM)
swap :: (a,b) -> (b,a)
swap (a,b) = (b,a)
ifSwap :: Bool -> (a, a) -> (a, a)
ifSwap b x =
if b then swap x else x
dup :: a -> (a, a)
dup a = (a,a)
i2d :: Integral a => a -> Double
i2d v =
fromIntegral v :: Double
integerToInt :: Integer -> Int
integerToInt t =
fromInteger t :: Int
(<<) :: Monad m => m b -> m a -> m b
(<<) = flip (>>)
liftM2' :: Monad m => m a -> (a -> b -> c) -> m b -> m c
liftM2' xs f = liftM2 f xs
liftM2_ :: Monad m => (a -> b -> c) -> m a -> m b -> m ()
liftM2_ f x y = liftM2 f x y >> return ()
ifM :: Monad m => m Bool -> m a -> m a -> m a
ifM f g h = f >>= \b -> if b then g else h
ifF :: Monad m => a -> (a -> m Bool) -> (a -> m b) -> (a -> m b) -> m b
ifF a f g h = f a >>= \b -> if b then g a else h a
whenM :: Monad m => m Bool -> m () -> m ()
whenM f g = f >>= \x -> when x g
unlessM :: Monad m => m Bool -> m () -> m ()
unlessM f g = f >>= \x -> unless x g
zip' :: a -> b -> (a, b)
zip' a b = (a, b)
zipM' :: Monad m => m a -> m b -> m (a, b)
zipM' = liftM2 zip'
firstMap :: (b -> c) -> [(b, d)] -> [(c, d)]
firstMap = map . first
zipMap :: (a -> b, a -> c) -> a -> (b, c)
zipMap (g, h) s = (g s, h s)
unzipMap :: (a -> (b,c)) -> (a -> b, a -> c)
unzipMap h = (fst . h, snd . h)
trace :: ((a, c) -> (b, c)) -> a -> b
trace f b = c
where (c, d) = f (b, d)
floorToMultiple :: Integral a => a -> a -> a
floorToMultiple x y = x x `mod` y
cond :: Monad m => [(Bool, m ())] -> m ()
cond [] = return ()
cond ((True,action) : _) = action
cond ((False,_) : rest) = cond rest
condM :: Monad m => [(m Bool, m ())] -> m ()
condM [] = return ()
condM ((test,action) : rest) = test >>= \t -> if t then action else condM rest