enumerate-0.1.1: enumerate all the values in a finite type (automatically)

Safe HaskellNone
LanguageHaskell2010

Data.Enumerate.Extra

Description

 

Synopsis

Documentation

failed :: MonadThrow m => String -> m a Source

failed = throwM . userError

maybe2throw :: (a -> Maybe b) -> forall m. MonadThrow m => a -> m b Source

generalize a function that fails with Nothing.

list2throw :: (a -> [b]) -> forall m. MonadThrow m => a -> m b Source

generalize a function that fails with [].

either2throw :: (a -> Either SomeException b) -> forall m. MonadThrow m => a -> m b Source

generalize a function that fails with Left.

throw2maybe :: (forall m. MonadThrow m => a -> m b) -> a -> Maybe b Source

specialization

throw2either :: (forall m. MonadThrow m => a -> m b) -> a -> Either SomeException b Source

specialization

throw2list :: (forall m. MonadThrow m => a -> m b) -> a -> [b] Source

specialization

totalizeFunction :: (NFData b, MonadThrow m) => (a -> b) -> a -> m b Source

makes an *unsafely*-partial function (i.e. a function that throws exceptions or that has inexhaustive pattern matching) into a *safely*-partial function (i.e. that explicitly returns in a monad that supports failure).

spoonWith :: (NFData a, MonadThrow m) => [Handler (m a)] -> a -> m a Source

Evaluate a value to normal form and throwM any exceptions are thrown during evaluation. For any error-free value, spoon = Just.

taken from the spoon package.

showsPrecWith :: (Show a, Show b) => String -> (a -> b) -> Int -> a -> ShowS Source

the eliminator as a function and the introducer as a string

helper for declaring Show instances of datatypes without visible constructors (like Map which is shown as an list).

powerSet :: Ord a => Set a -> Set (Set a) Source

the power set of a set of values.

>>> (powerset2matrix . powerSet . Set.fromList) [1..3]
[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]

dropEach :: Ord a => Set a -> Set (Set a) Source

>>> (powerset2matrix . dropEach . Set.fromList) [1..3]
[[1,2],[1,3],[2,3]]

powerset2matrix :: Set (Set a) -> [[a]] Source

convert a power set to an isomorphic matrix, sorting the entries.

(for doctest)