Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Lambdabot.Util
Description
String and other utilities
- concatWith :: [a] -> [[a]] -> [a]
- split :: Eq a => [a] -> [a] -> [[a]]
- split2 :: Char -> Int -> String -> [String]
- breakOnGlue :: Eq a => [a] -> [a] -> ([a], [a])
- clean :: Char -> [Char]
- dropSpace :: [Char] -> [Char]
- dropSpaceEnd :: [Char] -> [Char]
- dropNL :: [Char] -> [Char]
- snoc :: a -> [a] -> [a]
- after :: String -> String -> String
- splitFirstWord :: String -> (String, String)
- firstWord :: String -> String
- debugStr :: MonadIO m => String -> m ()
- debugStrLn :: MonadIO m => [Char] -> m ()
- lowerCaseString :: String -> String
- upperCaseString :: String -> String
- upperize :: String -> String
- lowerize :: String -> String
- quote :: String -> String
- timeStamp :: ClockTime -> String
- listToStr :: String -> [String] -> String
- showWidth :: Int -> Int -> String
- listToMaybeWith :: ([a] -> b) -> [a] -> Maybe b
- listToMaybeAll :: [a] -> Maybe [a]
- getRandItem :: RandomGen g => [a] -> g -> (a, g)
- stdGetRandItem :: [a] -> IO a
- randomElem :: [a] -> IO a
- showClean :: Show a => [a] -> String
- expandTab :: String -> String
- closest :: String -> [String] -> (Int, String)
- closests :: String -> [String] -> (Int, [String])
- withMWriter :: MVar a -> (a -> (a -> IO ()) -> IO b) -> IO b
- parIO :: IO a -> IO a -> IO a
- timeout :: Int -> IO a -> IO (Maybe a)
- choice :: (r -> Bool) -> (r -> a) -> (r -> a) -> r -> a
- arePrefixesWithSpaceOf :: [String] -> String -> Bool
- arePrefixesOf :: [String] -> String -> Bool
- (</>) :: FilePath -> FilePath -> FilePath
- (<.>) :: FilePath -> FilePath -> FilePath
- (<+>) :: FilePath -> FilePath -> FilePath
- (<>) :: FilePath -> FilePath -> FilePath
- (<$>) :: FilePath -> FilePath -> FilePath
- basename :: FilePath -> FilePath
- dirname :: FilePath -> FilePath
- dropSuffix :: FilePath -> FilePath
- joinPath :: FilePath -> FilePath -> FilePath
- addList :: Ord k => [(k, a)] -> Map k a -> Map k a
- mapMaybeMap :: Ord k => (a -> Maybe b) -> Map k a -> Map k b
- insertUpd :: Ord k => (a -> a) -> k -> a -> Map k a -> Map k a
- pprKeys :: Show k => Map k a -> String
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- unEither :: Either a a -> a
- io :: MonadIO m => IO a -> m a
- random :: MonadIO m => [a] -> m a
- insult :: [String]
- confirmation :: [String]
Documentation
Arguments
:: [a] | Glue to join with |
-> [[a]] | Elements to glue together |
-> [a] | Result: glued-together list |
concatWith
joins lists with the given glue elements. Example:
concatWith ", " ["one","two","three"] ===> "one, two, three"
Arguments
:: Eq a | |
=> [a] | Glue that holds pieces together |
-> [a] | List to break into pieces |
-> [[a]] | Result: list of pieces |
Split a list into pieces that were held together by glue. Example:
split ", " "one, two, three" ===> ["one","two","three"]
Arguments
:: Eq a | |
=> [a] | Glue that holds pieces together |
-> [a] | List from which to break off a piece |
-> ([a], [a]) | Result: (first piece, glue ++ rest of list) |
Break off the first piece of a list held together by glue, leaving the glue attached to the remainder of the list. Example: Like break, but works with a [a] match.
breakOnGlue ", " "one, two, three" ===> ("one", ", two, three")
clean :: Char -> [Char] Source
clean
takes a Char x and returns [x] unless the Char is '\CR' in
case [] is returned.
dropSpace :: [Char] -> [Char] Source
dropSpace
takes as input a String and strips spaces from the
prefix as well as the suffix of the String. Example:
dropSpace " abc " ===> "abc"
dropSpaceEnd :: [Char] -> [Char] Source
Drop space from the end of the string
Arguments
:: a | Element to be added |
-> [a] | List to add to |
-> [a] | Result: List ++ [Element] |
Reverse cons. Add an element to the back of a list. Example:
snoc 3 [2, 1] ===> [2, 1, 3]
Break a String into it's first word, and the rest of the string. Example:
split_first_word "A fine day" ===> ("A", "fine day)
firstWord :: String -> String Source
Get the first word of a string. Example:
first_word "This is a fine day" ===> "This"
debugStr :: MonadIO m => String -> m () Source
debugStr
checks if we have the verbose flag turned on. If we have
it outputs the String given. Else, it is a no-op.
debugStrLn :: MonadIO m => [Char] -> m () Source
debugStrLn
is a version of debugStr
that adds a newline to the end
of the string outputted.
lowerCaseString :: String -> String Source
lowerCaseString
transforms the string given to lower case.
Example: lowerCaseString "MiXeDCaSe" ===> "mixedcase"
upperCaseString :: String -> String Source
upperCaseString
transforms the string given to upper case.
Example: upperCaseString "MiXeDcaSe" ===> "MIXEDCASE"
upperize :: String -> String Source
upperize
forces the first char of a string to be uppercase.
if the string is empty, the empty string is returned.
lowerize :: String -> String Source
lowerize
forces the first char of a string to be lowercase.
if the string is empty, the empty string is returned.
quote :: String -> String Source
quote
puts a string into quotes but does not escape quotes in
the string itself.
listToStr :: String -> [String] -> String Source
Form a list of terms using a single conjunction. Example:
listToStr "and" ["a", "b", "c"] ===> "a, b and c"
Show a number, padded to the left with zeroes up to the specified width
listToMaybeWith :: ([a] -> b) -> [a] -> Maybe b Source
Like listToMaybe
, but take a function to use in case of a non-null list.
I.e. listToMaybe = listToMaybeWith head
listToMaybeAll :: [a] -> Maybe [a] Source
listToMaybeAll = listToMaybeWith id
Arguments
:: RandomGen g | |
=> [a] | The list to pick a random item from |
-> g | The RNG to use |
-> (a, g) | A pair of the item, and the new RNG seed |
getRandItem
takes as input a list and a random number generator. It
then returns a random element from the list, paired with the altered
state of the RNG
stdGetRandItem :: [a] -> IO a Source
stdGetRandItem
is the specialization of getRandItem
to the standard
RNG embedded within the IO monad. The advantage of using this is that
you use the Operating Systems provided RNG instead of rolling your own
and the state of the RNG is hidden, so one don't need to pass it
explicitly.
randomElem :: [a] -> IO a Source
closest :: String -> [String] -> (Int, String) Source
Find string in list with smallest levenshtein distance from first argument, return the string and the distance from pat it is. Will return the alphabetically first match if there are multiple matches (this may not be desirable, e.g. "mroe" -> "moo", not "more"
withMWriter :: MVar a -> (a -> (a -> IO ()) -> IO b) -> IO b Source
Thread-safe modification of an MVar.
arePrefixesWithSpaceOf :: [String] -> String -> Bool Source
arePrefixesOf :: [String] -> String -> Bool Source
dropSuffix :: FilePath -> FilePath Source
insertUpd :: Ord k => (a -> a) -> k -> a -> Map k a -> Map k a Source
This makes way more sense than insertWith
because we don't need to
remember the order of arguments of f
.
confirmation :: [String] Source