model-0.4.1: Derive a model of a data type using Generics

Safe HaskellSafe
LanguageHaskell2010

Data.Model.Util

Contents

Synopsis

Dependencies

properMutualGroups :: (Ord r, Pretty r, Foldable t) => (a -> Maybe r) -> Map r (t a) -> Either [String] [[r]] Source #

Return the groups of mutually dependent entities, with more than one component

>>> properMutualGroups Just (M.fromList [("a",["b","c"]),("b",["a","c"]),("c",[])])
Right [["b","a"]]

mutualGroups :: (Ord r, Pretty r, Foldable t) => (a -> Maybe r) -> Map r (t a) -> Either [String] [[r]] Source #

Return the groups of mutually dependent entities

>>> mutualGroups Just (M.fromList [("a",["b","c"]),("b",["a","c"]),("c",[])])
Right [["c"],["b","a"]]

transitiveClosure :: (Foldable t, Pretty r, Ord r) => (a -> Maybe r) -> Map r (t a) -> r -> Either [String] [r] Source #

Return the transitive closure of an element in a graph of dependencies specified as an adjacency list

>>> transitiveClosure Just (M.fromList [("a",["b","c"]),("b",["b","d","d","c"]),("c",[]),("d",["a"])]) "b"
Right ["c","a","d","b"]
>>> transitiveClosure Just (M.fromList [("a",["b","c"]),("b",["b","d","d","c"]),("c",[]),("d",["a"])]) "c"
Right ["c"]

Error utilities

type Errors = [Error] Source #

A list of error messages

toErrors :: Either Error a -> Either Errors a Source #

Either an error or a valid value type EitherError a = Either String a

Either errors or a valid value type EitherErrors a = Either [String] a

Convertible utilities

class Convertible a b where #

A typeclass that represents something that can be converted. A Convertible a b instance represents an a that can be converted to a b.

Minimal complete definition

safeConvert

Methods

safeConvert :: a -> ConvertResult b #

Convert a to b, returning Right on success and Left on error. For a simpler interface, see convert.

convert :: Convertible a b => a -> b #

Convert from one type of data to another. Raises an exception if there is an error with the conversion. For a function that does not raise an exception in that case, see safeConvert.

type ConvertResult a = Either ConvertError a #

The result of a safe conversion via safeConvert.

errorToConvertResult :: (Typeable b, Typeable a, Show a) => (a -> Either Error b) -> a -> ConvertResult b Source #

Formatting utilities

dotted :: [String] -> String Source #

Intercalate a dot between the non empty elements of a list of strings.

>>> dotted []
""
>>> dotted ["","bc","de"]
"bc.de"
>>> dotted ["bc","","de"]
"bc.de"

Orphan instances