ganeti-htoolsSource codeContentsIndex
Ganeti.HTools.Utils
Contents
Debug functions
Miscellaneous
Mathematical functions
Logical functions
Parsing utility functions
Description
Utility functions.
Synopsis
debug :: Show a => a -> a
debugFn :: Show b => (a -> b) -> a -> a
debugXy :: Show a => a -> b -> b
applyIf :: Bool -> (a -> a) -> a -> a
commaJoin :: [String] -> String
sepSplit :: Eq a => a -> [a] -> [[a]]
plural :: Int -> String -> String -> String
ensureQuoted :: String -> String
stdDev :: [Double] -> Double
if' :: Bool -> a -> a -> a
parseChoices :: (Monad m, Read a) => String -> String -> [(a, String)] -> m a
tryRead :: (Monad m, Read a) => String -> String -> m a
formatTable :: [[String]] -> [Bool] -> [[String]]
printTable :: String -> [String] -> [[String]] -> [Bool] -> String
parseUnitValue :: Monad m => String -> m Rational
parseUnit :: (Monad m, Integral a, Read a) => String -> m a
exitIfBad :: String -> Result a -> IO a
exitErr :: String -> IO a
exitWhen :: Bool -> String -> IO ()
exitUnless :: Bool -> String -> IO ()
Debug functions
debug :: Show a => a -> aSource
To be used only for debugging, breaks referential integrity.
debugFn :: Show b => (a -> b) -> a -> aSource
Displays a modified form of the second parameter before returning it.
debugXy :: Show a => a -> b -> bSource
Show the first parameter before returning the second one.
Miscellaneous
applyIf :: Bool -> (a -> a) -> a -> aSource
Apply the function if condition holds, otherwise use default value.
commaJoin :: [String] -> StringSource
Comma-join a string list.
sepSplit :: Eq a => a -> [a] -> [[a]]Source
Split a list on a separator and return an array.
plural :: Int -> String -> String -> StringSource
Simple pluralize helper
ensureQuoted :: String -> StringSource
Ensure a value is quoted if needed.
Mathematical functions
stdDev :: [Double] -> DoubleSource
Standard deviation function.
Logical functions
if'Source
::
=> Bool"then" result
-> a"else" result
-> a"then" or else result depending on the condition
-> a
"if" as a function, rather than as syntactic sugar.
Parsing utility functions
parseChoices :: (Monad m, Read a) => String -> String -> [(a, String)] -> m aSource
Parse results from readsPrec.
tryRead :: (Monad m, Read a) => String -> String -> m aSource
Safe read function returning data encapsulated in a Result.
formatTable :: [[String]] -> [Bool] -> [[String]]Source
Format a table of strings to maintain consistent length.
printTable :: String -> [String] -> [[String]] -> [Bool] -> StringSource
Constructs a printable table from given header and rows
parseUnitValue :: Monad m => String -> m RationalSource
Converts a unit (e.g. m or GB) into a scaling factor.
parseUnit :: (Monad m, Integral a, Read a) => String -> m aSource

Tries to extract number and scale from the given string.

Input must be in the format NUMBER+ SPACE* [UNIT]. If no unit is specified, it defaults to MiB. Return value is always an integral value in MiB.

exitIfBad :: String -> Result a -> IO aSource
Unwraps a Result, exiting the program if it is a Bad value, otherwise returning the actual contained value.
exitErr :: String -> IO aSource
Exits immediately with an error message.
exitWhen :: Bool -> String -> IO ()Source
Exits with an error message if the given boolean condition if true.
exitUnless :: Bool -> String -> IO ()Source
Exits with an error message unless the given boolean condition if true, the opposite of exitWhen.
Produced by Haddock version 2.6.0