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

Safe HaskellSafe-Inferred

Game.Goatee.Common

Description

Common utilities used throughout the project.

Synopsis

Documentation

listDeleteIndex :: 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.

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.

fromLeft :: Either a b -> aSource

Extracts a left value from an Either.

fromRight :: Either a b -> bSource

Extracts a right value from an Either.

onLeft :: (a -> c) -> Either a b -> Either c bSource

Transforms the left value of an Either, leaving a right value alone.

onRight :: (b -> c) -> Either a b -> Either a cSource

Transforms the right value of an Either, leaving a left value alone. This is just fmap, but looks nicer when used beside onLeft.

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.

whenMaybe :: Monad m => Maybe a -> (a -> m ()) -> m ()Source

Executes the monadic function if a Maybe contains a value.

cond :: a -> [(Bool, a)] -> aSource

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 -> aSource

A function form of if that takes its test last.

andM :: Monad m => [m Bool] -> m BoolSource

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 bSource

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.

newtype Seq m Source

This sequences ()-valued monadic actions as a monoid. If m is some monad, then Seq m is a monoid where mempty does nothing and mappend sequences actions via >>.

Constructors

Seq (m ()) 

Instances

Monad m => Monoid (Seq m)