| Safe Haskell | Safe |
|---|---|
| Language | Haskell98 |
Game.Goatee.Common
Description
Common utilities used throughout the project.
- listDeleteAt :: Int -> [a] -> [a]
- listInsertAt :: Int -> a -> [a] -> [a]
- listReplace :: Eq a => a -> a -> [a] -> [a]
- listUpdate :: Show a => (a -> a) -> Int -> [a] -> [a]
- andEithers :: [Either a b] -> Either [a] [b]
- for :: [a] -> (a -> b) -> [b]
- mapTuple :: (a -> b) -> (a, a) -> (b, b)
- mapInvert :: Ord v => Map k v -> Map v [k]
- whenMaybe :: Monad m => Maybe a -> (a -> m ()) -> m ()
- cond :: a -> [(Bool, a)] -> a
- if' :: a -> a -> Bool -> a
- andM :: Monad m => [m Bool] -> m Bool
- forIndexM_ :: Monad m => [a] -> (Int -> a -> m ()) -> m ()
- whileM :: Monad m => m Bool -> m () -> m ()
- whileM' :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()
- doWhileM :: Monad m => a -> (a -> m (Either b a)) -> m b
Documentation
listDeleteAt :: Int -> [a] -> [a] Source #
Drops the element at an index from a list. If the index is out of bounds then the list is returned unmodified.
listInsertAt :: Int -> a -> [a] -> [a] Source #
Inserts the element into the list before the given position. If the position is less than 0 or greater than the length of the list, then the index is clamped to this range.
listReplace :: Eq a => a -> a -> [a] -> [a] Source #
listReplace old new list replaces all occurrences of old with new in
list.
listUpdate :: Show a => (a -> a) -> Int -> [a] -> [a] Source #
Modifies the element at a specific index in a list.
andEithers :: [Either a b] -> Either [a] [b] Source #
whenMaybe :: Monad m => Maybe a -> (a -> m ()) -> m () Source #
Executes the monadic function if a Maybe contains a value.
cond :: a -> [(Bool, a)] -> a Source #
Finds the first tuple whose first element is true, and returns its second
element. If all of the first values are false, then the first argument to
cond is returned instead.
andM :: Monad m => [m Bool] -> m Bool Source #
and in a monad. Executes the actions in the list in order. If any
action returns false then the remaining actions are skipped and the result is
false. Otherwise all actions returned true, and the result is true. An
empty list returns true.
forIndexM_ :: Monad m => [a] -> (Int -> a -> m ()) -> m () Source #
forM_ that also passes in the index of each element.
whileM :: Monad m => m Bool -> m () -> m () Source #
whileM test body repeatedly evaluates test until it returns false.
Every time test returns true, body is executed once.