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 |
Utility functions that can't be found in the libraries but should be shared across Hets.
- 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
- 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 :: Monad m => (a -> m [b]) -> [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)
- 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 ())
- verbMsg :: Handle -> Int -> Int -> String -> IO ()
- verbMsgLn :: Handle -> Int -> Int -> String -> IO ()
- verbMsgIO :: Int -> Int -> String -> IO ()
- verbMsgIOLn :: Int -> Int -> String -> IO ()
Documentation
isSingleton :: Set a -> Bool
O(1) test if the set's size is one
replace :: Eq a => [a] -> [a] -> [a] -> [a]
replace all occurrences of the first (non-empty sublist) argument with the second argument in the third (list) argument.
combine :: [[a]] -> [[a]]
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!)
:: 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])
generalization of mapAccumL to monads with combine function
concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
Monadic version of concatMap taken from http:/darcs.haskell.orgghccompilerutils/MonadUtils.hs
:: 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]
split a colon (or on windows semicolon) separated list of paths
:: 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]]
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)
If the given string is terminated by a decimal number this number and the nonnumber prefix is returned.
basename :: FilePath -> FilePath
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
A function inspired by a perl function from the standard perl-module File::Basename. It gives the directory part of a filepath.
:: [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.
:: 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
:: 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
filterMapWithList :: Ord k => [k] -> Map k e -> Map k e
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)
the timeout function taking seconds instead of microseconds
:: 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
timeoutCommand :: Int -> FilePath -> [String] -> IO (Maybe (ExitCode, String, String))
runs a command with timeout
withinDirectory :: FilePath -> IO a -> IO a
runs an action in a different directory without changing the current directory globally.
:: String | Content |
-> FilePath | Directory in which to create the file |
-> String | File name template |
-> IO FilePath | create file |
calls openTempFile but directly writes content and closes the file
create file in temporary directory (the first argument is the content)
getTempFifo :: String -> IO FilePath
Writes the message to the given handle unless the verbosity is less than the message level.