Hets - the Heterogeneous Tool Set
Copyright(c) Klaus Luettich Uni Bremen 2002-2006
LicenseGPLv2 or higher, see LICENSE.txt
MaintainerChristian.Maeder@dfki.de
Stabilityprovisional
Portabilityportable
Safe HaskellNone

Common.Utils

Description

Utility functions that can't be found in the libraries but should be shared across Hets.

Synopsis

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.

hasMany :: Set a -> Bool Source #

O(1) test if the set's size is greater one

number :: [a] -> [(a, Int)] Source #

add indices to a list starting from one

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!)

trim :: String -> String Source #

trims a string both on left and right hand side

trimLeft :: String -> String Source #

trims a string only on the left side

trimRight :: String -> String Source #

trims a string only on the right side

toSnakeCase :: String -> String Source #

nubOrd :: Ord a => [a] -> [a] Source #

nubOrdOn :: Ord b => (a -> b) -> [a] -> [a] Source #

atMaybe :: [a] -> Int -> Maybe a Source #

safe variant of !!

readMaybe :: Read a => String -> Maybe a Source #

mapAccumLM 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

keepMins :: (a -> a -> Bool) -> [a] -> [a] Source #

keep only minimal elements

splitOn Source #

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

splitBy Source #

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.

fileparse Source #

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.

stripDir :: FilePath -> (FilePath, FilePath) Source #

stripSuffix :: [String] -> FilePath -> (FilePath, Maybe String) Source #

makeRelativeDesc 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

getEnvSave Source #

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

getEnvDef Source #

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

executeProcess Source #

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.

writeTempFile Source #

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

getTempFile Source #

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 #

readFifo :: FilePath -> IO ([String], IO ()) Source #

tryToStripPrefix :: String -> String -> String Source #

strip a prefix from a string, if possible

verbMsg Source #

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

verbMsgIO :: Int -> Int -> String -> IO () Source #

verbMsg with stdout as handle

verbMsgIOLn :: Int -> Int -> String -> IO () Source #

verbMsgLn with stdout as handle

data FileInfo Source #

Constructors

FileInfo 

Fields