goatee-0.3.1.3: A monadic take on a 2,500-year-old board game - library.

Safe HaskellSafe
LanguageHaskell98

Game.Goatee.Common

Description

Common utilities used throughout the project.

Synopsis

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 #

If any item is a Left, then the list of Lefts is returned, otherwise the list of Rights is returned.

for :: [a] -> (a -> b) -> [b] Source #

for is flip map.

mapTuple :: (a -> b) -> (a, a) -> (b, b) Source #

Transforms both values in a homogeneous tuple.

mapInvert :: Ord v => Map k v -> Map v [k] Source #

Inverts a map, collecting all of the keys that map to a single value in one list in the result map. No guarantees are made on the order of the keys in each value's list. If you want the results in ascending order, apply map sort to the result.

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.

if' :: a -> a -> Bool -> a Source #

A function form of if that takes its test last.

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.

whileM' :: Monad m => m (Maybe a) -> (a -> m ()) -> m () Source #

whileM' test body repeatedly evaluates test until it returns Nothing. Every time it returns a Just, that value is passed to body and the result is executed.

doWhileM :: Monad m => a -> (a -> m (Either b a)) -> m b Source #

doWhileM init body repeatedly calls body with init. As long as body returns a Right value, it is re-executed with the returned value. When it returns a Left value, the loop stops and the value is returned.