| Copyright | (c) Klaus Luettich Uni Bremen 2002-2006 | 
|---|---|
| License | GPLv2 or higher, see LICENSE.txt | 
| Maintainer | Christian.Maeder@dfki.de | 
| Stability | provisional | 
| Portability | portable | 
| Safe Haskell | None | 
Common.Utils
Description
Utility functions that can't be found in the libraries but should be shared across Hets.
Synopsis
- isSingleton :: Set a -> Bool
 - replace :: Eq a => [a] -> [a] -> [a] -> [a]
 - hasMany :: Set a -> Bool
 - number :: [a] -> [(a, Int)]
 - combine :: [[a]] -> [[a]]
 - trim :: String -> String
 - trimLeft :: String -> String
 - trimRight :: String -> String
 - toSnakeCase :: String -> String
 - nubOrd :: Ord a => [a] -> [a]
 - nubOrdOn :: Ord b => (a -> b) -> [a] -> [a]
 - atMaybe :: [a] -> Int -> Maybe a
 - readMaybe :: Read a => String -> Maybe a
 - mapAccumLM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
 - mapAccumLCM :: Monad m => (a -> b -> c) -> (acc -> a -> m (acc, b)) -> acc -> [a] -> m (acc, [c])
 - concatMapM :: (Traversable t, Monad m) => (a -> m [b]) -> t a -> m [b]
 - composeMap :: Ord a => Map a b -> Map a a -> Map a a -> Map a a
 - keepMins :: (a -> a -> Bool) -> [a] -> [a]
 - splitOn :: Eq a => a -> [a] -> [[a]]
 - splitPaths :: String -> [FilePath]
 - splitBy :: Eq a => a -> [a] -> [[a]]
 - splitByList :: Eq a => [a] -> [a] -> [[a]]
 - numberSuffix :: String -> Maybe (String, Int)
 - basename :: FilePath -> FilePath
 - dirname :: FilePath -> FilePath
 - fileparse :: [String] -> FilePath -> (FilePath, FilePath, Maybe String)
 - stripDir :: FilePath -> (FilePath, FilePath)
 - stripSuffix :: [String] -> FilePath -> (FilePath, Maybe String)
 - makeRelativeDesc :: FilePath -> FilePath -> FilePath
 - getEnvSave :: a -> String -> (String -> Maybe a) -> IO a
 - getEnvDef :: String -> String -> IO String
 - filterMapWithList :: Ord k => [k] -> Map k e -> Map k e
 - timeoutSecs :: Int -> IO a -> IO (Maybe a)
 - executeProcess :: FilePath -> [String] -> String -> IO (ExitCode, String, String)
 - executeProcessWithEnvironment :: FilePath -> [String] -> String -> [(String, String)] -> IO (ExitCode, String, String)
 - timeoutCommand :: Int -> FilePath -> [String] -> IO (Maybe (ExitCode, String, String))
 - withinDirectory :: FilePath -> IO a -> IO a
 - writeTempFile :: String -> FilePath -> String -> IO FilePath
 - getTempFile :: String -> String -> IO FilePath
 - getTempFifo :: String -> IO FilePath
 - readFifo :: FilePath -> IO ([String], IO ())
 - tryToStripPrefix :: String -> String -> String
 - verbMsg :: Handle -> Int -> Int -> String -> IO ()
 - verbMsgLn :: Handle -> Int -> Int -> String -> IO ()
 - verbMsgIO :: Int -> Int -> String -> IO ()
 - verbMsgIOLn :: Int -> Int -> String -> IO ()
 - data FileInfo = FileInfo {
- wasDownloaded :: Bool
 - filePath :: FilePath
 
 
Documentation
isSingleton :: Set a -> Bool Source #
O(1) test if the set's size is one
replace :: Eq a => [a] -> [a] -> [a] -> [a] Source #
replace all occurrences of the first (non-empty sublist) argument with the second argument in the third (list) argument.
combine :: [[a]] -> [[a]] Source #
Transform a list [l1, l2, ... ln] to (in sloppy notation)
     [[x1, x2, ... xn] | x1 <- l1, x2 <- l2, ... xn <- ln]
     (this is just the sequence function!) 
toSnakeCase :: String -> String Source #
Arguments
| :: Monad m | |
| => (acc -> x -> m (acc, y)) | Function taking accumulator and list element, returning new accumulator and modified list element  | 
| -> acc | Initial accumulator  | 
| -> [x] | Input list  | 
| -> m (acc, [y]) | Final accumulator and result list  | 
generalization of mapAccumL to monads
mapAccumLCM :: Monad m => (a -> b -> c) -> (acc -> a -> m (acc, b)) -> acc -> [a] -> m (acc, [c]) Source #
generalization of mapAccumL to monads with combine function
concatMapM :: (Traversable t, Monad m) => (a -> m [b]) -> t a -> m [b] Source #
Monadic version of concatMap taken from http://darcs.haskell.org/ghc/compiler/utils/MonadUtils.hs
composeMap :: Ord a => Map a b -> Map a a -> Map a a -> Map a a Source #
composition of arbitrary maps
Arguments
| :: Eq a | |
| => a | separator  | 
| -> [a] | list to split  | 
| -> [[a]] | 
A function inspired by the perl function split. A list is splitted on a separator element in smaller non-empty lists. The separator element is dropped from the resulting list.
splitPaths :: String -> [FilePath] Source #
split a colon (or on windows semicolon) separated list of paths
Arguments
| :: Eq a | |
| => a | separator  | 
| -> [a] | list to split  | 
| -> [[a]] | 
Same as splitOn but empty lists are kept. Even the empty list is split into a singleton list containing the empty list.
splitByList :: Eq a => [a] -> [a] -> [[a]] Source #
Same as splitBy but the separator is a sublist not only one element. Note that the separator must be non-empty.
numberSuffix :: String -> Maybe (String, Int) Source #
If the given string is terminated by a decimal number this number and the nonnumber prefix is returned.
basename :: FilePath -> FilePath Source #
A function inspired by a perl function from the standard perl-module File::Basename. It removes the directory part of a filepath.
dirname :: FilePath -> FilePath Source #
A function inspired by a perl function from the standard perl-module File::Basename. It gives the directory part of a filepath.
Arguments
| :: [String] | list of suffixes  | 
| -> FilePath | |
| -> (FilePath, FilePath, Maybe String) | (basename,directory,matched suffix)  | 
A function inspired by a perl function from the standard perl-module File::Basename. It splits a filepath into the basename, the directory and gives the suffix that matched from the list of suffixes. If a suffix matched it is removed from the basename.
stripSuffix :: [String] -> FilePath -> (FilePath, Maybe String) Source #
Arguments
| :: FilePath | path to a directory  | 
| -> FilePath | to be computed relatively to given directory  | 
| -> FilePath | resulting relative path  | 
This function generalizes makeRelative in that it computes also a relative path with descents such as ....test.txt
Arguments
| :: a | default value  | 
| -> String | name of environment variable  | 
| -> (String -> Maybe a) | parse and check value of variable  | 
| -> IO a | 
get, parse and check an environment variable; provide the default value, only if the envionment variable is not set or the parse-check-function returns Nothing
Arguments
| :: String | environment variable  | 
| -> String | default value  | 
| -> IO String | 
get environment variable
filterMapWithList :: Ord k => [k] -> Map k e -> Map k e Source #
filter a map according to a given list of keys (it dosen't hurt if a key is not present in the map)
timeoutSecs :: Int -> IO a -> IO (Maybe a) Source #
the timeout function taking seconds instead of microseconds
Arguments
| :: FilePath | command to run  | 
| -> [String] | any arguments  | 
| -> String | standard input  | 
| -> IO (ExitCode, String, String) | exitcode, stdout, stderr  | 
like readProcessWithExitCode, but checks the command argument first
executeProcessWithEnvironment :: FilePath -> [String] -> String -> [(String, String)] -> IO (ExitCode, String, String) Source #
timeoutCommand :: Int -> FilePath -> [String] -> IO (Maybe (ExitCode, String, String)) Source #
runs a command with timeout
withinDirectory :: FilePath -> IO a -> IO a Source #
runs an action in a different directory without changing the current directory globally.
Arguments
| :: String | Content  | 
| -> FilePath | Directory in which to create the file  | 
| -> String | File name template  | 
| -> IO FilePath | create file  | 
opens a temp file but directly writes content and closes the file
Arguments
| :: String | Content  | 
| -> String | File name template  | 
| -> IO FilePath | create file  | 
create file in temporary directory (the first argument is the content)
getTempFifo :: String -> IO FilePath Source #
tryToStripPrefix :: String -> String -> String Source #
strip a prefix from a string, if possible
Arguments
| :: Handle | Output handle  | 
| -> Int | global verbosity  | 
| -> Int | message level  | 
| -> String | message level  | 
| -> IO () | 
Writes the message to the given handle unless the verbosity is less than the message level.
verbMsgLn :: Handle -> Int -> Int -> String -> IO () Source #
Same as verbMsg but with a newline at the end
verbMsgIOLn :: Int -> Int -> String -> IO () Source #
verbMsgLn with stdout as handle