guard curses and sdl module by flags
[intricacy.git] / Util.hs
blob3c5aaec7ce20c9329d08402fefba09f73a92648b
1 -- This file is part of Intricacy
2 -- Copyright (C) 2013 Martin Bays <mbays@sdf.org>
3 --
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
7 --
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
11 module Util where
12 import qualified Data.Vector as Vector
13 import Data.Vector (Vector)
14 import Control.Monad
15 import Control.Monad.Trans.Maybe
17 enumVec :: Vector a -> [(Int,a)]
18 enumVec = Vector.toList . Vector.indexed
20 liftMaybe :: Monad m => Maybe a -> MaybeT m a
21 liftMaybe = MaybeT . return
23 -- nice tip from one joeyh:
24 whenM,unlessM,(>>?),(>>!) :: Monad m => m Bool -> m () -> m ()
25 whenM c a = c >>= flip when a
26 unlessM c a = c >>= flip unless a
27 (>>?) = whenM
28 (>>!) = unlessM
29 -- same precedence as ($), allowing e.g. foo bar >>! error $ "failed " ++ meep
30 infixr 0 >>?
31 infixr 0 >>!
33 -- |fi: just a straight abbreviation for fromIntegral
34 fi :: (Integral a, Num b) => a -> b
35 fi = fromIntegral