-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Extra functions I use. -- -- A library of extra functions for the standard Haskell libraries. Most -- functions are new, and add missing functionality. Some are available -- in later versions of GHC, but this package ports them back to GHC 7.2. @package extra @version 0.2 module System.Environment.Extra -- | Returns the absolute pathname of the current executable. -- -- Note that for scripts and interactive sessions, this is the path to -- the interpreter (e.g. ghci.) getExecutablePath :: IO FilePath -- | Return the value of the environment variable var, or -- Nothing if there is no such value. -- -- For POSIX users, this is equivalent to getEnv. lookupEnv :: String -> IO (Maybe String) module Numeric.Extra showDP :: RealFloat a => Int -> a -> String intToDouble :: Int -> Double intToFloat :: Int -> Float floatToDouble :: Float -> Double doubleToFloat :: Double -> Float module System.Time.Extra sleep :: Double -> IO () subtractTime :: UTCTime -> UTCTime -> Double showTime :: Double -> String -- | Call once at the start, then call repeatedly to get Time values out offsetTime :: IO (IO Double) -- | Like offsetTime, but results will never decrease (though they may stay -- the same) offsetTimeIncrease :: IO (IO Double) duration :: IO a -> IO (Double, a) module Data.Tuple.Extra dupe :: a -> (a, a) fst3 :: (a, b, c) -> a snd3 :: (a, b, c) -> b thd3 :: (a, b, c) -> c concat2 :: [([a], [b])] -> ([a], [b]) concat3 :: [([a], [b], [c])] -> ([a], [b], [c]) -- | This module extends Data.List with extra functions of a similar -- nature. The package also exports the existing Data.List -- functions. Some of the names and semantics were inspired by the -- text package. module Data.List.Extra lower :: String -> String upper :: String -> String strip :: String -> String stripStart :: String -> String stripEnd :: String -> String dropAround :: (a -> Bool) -> [a] -> [a] word1 :: String -> (String, String) drop1 :: [a] -> [a] list :: b -> (a -> [a] -> b) -> [a] -> b uncons :: [a] -> Maybe (a, [a]) unsnoc :: [a] -> Maybe ([a], a) cons :: a -> [a] -> [a] snoc :: [a] -> a -> [a] groupSort :: Ord k => [(k, v)] -> [(k, [v])] groupSortOn :: Ord a => (k -> a) -> [(k, v)] -> [(k, [v])] nubOn :: Eq b => (a -> b) -> [a] -> [a] groupOn :: Eq b => (a -> b) -> [a] -> [[a]] sortOn :: Ord b => (a -> b) -> [a] -> [a] chop :: ([a] -> (b, [a])) -> [a] -> [b] for :: [a] -> (a -> b) -> [b] rep :: Eq a => a -> a -> a -> a reps :: Eq a => a -> a -> [a] -> [a] disjoint :: Eq a => [a] -> [a] -> Bool distinct :: Eq a => [a] -> Bool dropEnd :: Int -> [a] -> [a] takeEnd :: Int -> [a] -> [a] breakEnd :: (a -> Bool) -> [a] -> ([a], [a]) spanEnd :: (a -> Bool) -> [a] -> ([a], [a]) -- | The dropWhileEnd function drops the largest suffix of a list in -- which the given predicate holds for all elements. For example: -- --
-- dropWhileEnd isSpace "foo\n" == "foo"
-- dropWhileEnd isSpace "foo bar" == "foo bar"
-- dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined
--
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
takeWhileEnd :: (a -> Bool) -> [a] -> [a]
-- | Return the prefix of the second string if its suffix matches the
-- entire first string.
--
-- Examples:
--
-- -- stripSuffix "bar" "foobar" == Just "foo" -- stripSuffix "" "baz" == Just "baz" -- stripSuffix "foo" "quux" == Nothing --stripSuffix :: Eq a => [a] -> [a] -> Maybe [a] concatUnzip :: [([a], [b])] -> ([a], [b]) merge :: Ord a => [a] -> [a] -> [a] mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] replace :: String -> String -> String -> String wordsBy :: (a -> Bool) -> [a] -> [[a]] linesBy :: (a -> Bool) -> [a] -> [[a]] firstJust :: (a -> Maybe b) -> [a] -> Maybe b -- | Find the first instance of needle in haystack. The -- first element of the returned tuple is the prefix of haystack -- before needle is matched. The second is the remainder of -- haystack, starting with the match. -- -- Examples: -- --
-- breakOn "::" "a::b::c" == ("a", "::b::c")
-- breakOn "/" "foobar" == ("foobar", "")
--
--
-- Laws:
--
-- -- \needle haystack -> let (prefix,match) = breakOn needle haystack in prefix ++ match == haystack --breakOn :: Eq a => [a] -> [a] -> ([a], [a]) -- | Similar to breakOn, but searches from the end of the string. -- -- The first element of the returned tuple is the prefix of -- haystack up to and including the last match of -- needle. The second is the remainder of haystack, -- following the match. -- --
-- breakOnEnd "::" "a::b::c" == ("a::b::", "c")
--
breakOnEnd :: Eq a => [a] -> [a] -> ([a], [a])
-- | Break a list into pieces separated by the first list argument,
-- consuming the delimiter. An empty delimiter is invalid, and will cause
-- an error to be raised.
--
-- Examples:
--
-- -- splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"] -- splitOn "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""] -- splitOn "x" "x" == ["",""] -- splitOn "x" "" == [""] ---- -- and -- --
-- \s x -> s /= "" ==> intercalate s (splitOn s x) == x -- \c x -> splitOn [c] x == split (==c) x --splitOn :: Eq a => [a] -> [a] -> [[a]] -- | Splits a list into components delimited by separators, where the -- predicate returns True for a separator element. The resulting -- components do not contain the separators. Two adjacent separators -- result in an empty component in the output. eg. -- --
-- split (=='a') "aabbaca" == ["","","bb","c",""] -- split (=='a') "" == [""] --split :: (a -> Bool) -> [a] -> [[a]] chunksOf :: Int -> [a] -> [[a]] module Data.IORef.Extra -- | Strict version of modifyIORef modifyIORef' :: IORef a -> (a -> a) -> IO () writeIORef' :: IORef a -> a -> IO () -- | Strict version of atomicModifyIORef. This forces both the value -- stored in the IORef as well as the value returned. atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b -- | Variant of writeIORef with the "barrier to reordering" property -- that atomicModifyIORef has. atomicWriteIORef :: IORef a -> a -> IO () atomicWriteIORef' :: IORef a -> a -> IO () module Data.Either.Extra isLeft :: Either t t1 -> Bool isRight :: Either t t1 -> Bool fromLeft :: Either t t1 -> t fromRight :: Either t t1 -> t1 fromEither :: Either a a -> a module Control.Monad.Extra whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () unit :: m () -> m () partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a]) concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] loopM :: Monad m => (a -> m (Either a b)) -> a -> m b whileM :: Monad m => m Bool -> m () ifM :: Monad m => m Bool -> m a -> m a -> m a notM :: Functor m => m Bool -> m Bool (||^) :: Monad m => m Bool -> m Bool -> m Bool (&&^) :: Monad m => m Bool -> m Bool -> m Bool orM :: Monad m => [m Bool] -> m Bool andM :: Monad m => [m Bool] -> m Bool anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool allM :: Monad m => (a -> m Bool) -> [a] -> m Bool findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a) firstJustM :: Monad m => (a -> m (Maybe b)) -> [a] -> m (Maybe b) module System.Directory.Extra withCurrentDirectory :: FilePath -> IO a -> IO a getDirectoryContentsRecursive :: FilePath -> IO [FilePath] module Control.Exception.Extra retry :: Int -> IO a -> IO a -- | Print an exception, but if that exception itself contains exceptions, -- simply print <NestedException>. Since Haskell is a lazy -- language it is possible to throw exceptions that are themselves -- undefined. This function is useful to report them to users. showException :: SomeException -> IO String -- | Ignore any exceptions thrown by the action and continue as normal. ignore :: IO () -> IO () catch_ :: IO a -> (SomeException -> IO a) -> IO a handle_ :: (SomeException -> IO a) -> IO a -> IO a try_ :: IO a -> IO (Either SomeException a) catchJust_ :: (SomeException -> Maybe b) -> IO a -> (b -> IO a) -> IO a handleJust_ :: (SomeException -> Maybe b) -> (b -> IO a) -> IO a -> IO a tryJust_ :: (SomeException -> Maybe b) -> IO a -> IO (Either b a) catchBool :: Exception e => (e -> Bool) -> IO a -> (e -> IO a) -> IO a handleBool :: Exception e => (e -> Bool) -> (e -> IO a) -> IO a -> IO a tryBool :: Exception e => (e -> Bool) -> IO a -> IO (Either e a) module System.Info.Extra isWindows :: Bool getProcessorCount :: IO Int -- | More advanced temporary file manipulation functions can be found in -- the exceptions package. module System.IO.Extra readFileEncoding :: TextEncoding -> FilePath -> IO String readFileUTF8 :: FilePath -> IO String readFileBinary :: FilePath -> IO String readFile' :: FilePath -> IO String readFileEncoding' :: TextEncoding -> FilePath -> IO String readFileUTF8' :: FilePath -> IO String readFileBinary' :: FilePath -> IO String writeFileEncoding :: TextEncoding -> FilePath -> String -> IO () writeFileUTF8 :: FilePath -> String -> IO () writeFileBinary :: FilePath -> String -> IO () withTempFile :: (FilePath -> IO a) -> IO a withTempDir :: (FilePath -> IO a) -> IO a captureOutput :: IO () -> IO String withBuffering :: Handle -> BufferMode -> IO a -> IO a module Control.Concurrent.Extra -- | On GHC 7.6 and above with the -threaded flag, brackets a call -- to setNumCapabilities. On lower versions (which lack -- setNumCapabilities) this function just runs the argument -- action. withNumCapabilities :: Int -> IO a -> IO a -- | A version of setNumCapabilities that works on all versions of -- GHC, but has no effect before GHC 7.6. setNumCapabilities :: Int -> IO () module Extra -- | On GHC 7.6 and above with the -threaded flag, brackets a call -- to setNumCapabilities. On lower versions (which lack -- setNumCapabilities) this function just runs the argument -- action. withNumCapabilities :: Int -> IO a -> IO a -- | A version of setNumCapabilities that works on all versions of -- GHC, but has no effect before GHC 7.6. setNumCapabilities :: Int -> IO () retry :: Int -> IO a -> IO a -- | Print an exception, but if that exception itself contains exceptions, -- simply print <NestedException>. Since Haskell is a lazy -- language it is possible to throw exceptions that are themselves -- undefined. This function is useful to report them to users. showException :: SomeException -> IO String -- | Ignore any exceptions thrown by the action and continue as normal. ignore :: IO () -> IO () catch_ :: IO a -> (SomeException -> IO a) -> IO a handle_ :: (SomeException -> IO a) -> IO a -> IO a try_ :: IO a -> IO (Either SomeException a) catchJust_ :: (SomeException -> Maybe b) -> IO a -> (b -> IO a) -> IO a handleJust_ :: (SomeException -> Maybe b) -> (b -> IO a) -> IO a -> IO a tryJust_ :: (SomeException -> Maybe b) -> IO a -> IO (Either b a) catchBool :: Exception e => (e -> Bool) -> IO a -> (e -> IO a) -> IO a handleBool :: Exception e => (e -> Bool) -> (e -> IO a) -> IO a -> IO a tryBool :: Exception e => (e -> Bool) -> IO a -> IO (Either e a) whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () unit :: m () -> m () partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a]) concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] loopM :: Monad m => (a -> m (Either a b)) -> a -> m b whileM :: Monad m => m Bool -> m () ifM :: Monad m => m Bool -> m a -> m a -> m a notM :: Functor m => m Bool -> m Bool (||^) :: Monad m => m Bool -> m Bool -> m Bool (&&^) :: Monad m => m Bool -> m Bool -> m Bool orM :: Monad m => [m Bool] -> m Bool andM :: Monad m => [m Bool] -> m Bool anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool allM :: Monad m => (a -> m Bool) -> [a] -> m Bool findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a) firstJustM :: Monad m => (a -> m (Maybe b)) -> [a] -> m (Maybe b) isLeft :: Either t t1 -> Bool isRight :: Either t t1 -> Bool fromLeft :: Either t t1 -> t fromRight :: Either t t1 -> t1 fromEither :: Either a a -> a -- | Strict version of modifyIORef modifyIORef' :: IORef a -> (a -> a) -> IO () writeIORef' :: IORef a -> a -> IO () -- | Strict version of atomicModifyIORef. This forces both the value -- stored in the IORef as well as the value returned. atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b -- | Variant of writeIORef with the "barrier to reordering" property -- that atomicModifyIORef has. atomicWriteIORef :: IORef a -> a -> IO () atomicWriteIORef' :: IORef a -> a -> IO () lower :: String -> String upper :: String -> String strip :: String -> String stripStart :: String -> String stripEnd :: String -> String dropAround :: (a -> Bool) -> [a] -> [a] word1 :: String -> (String, String) drop1 :: [a] -> [a] list :: b -> (a -> [a] -> b) -> [a] -> b uncons :: [a] -> Maybe (a, [a]) unsnoc :: [a] -> Maybe ([a], a) cons :: a -> [a] -> [a] snoc :: [a] -> a -> [a] groupSort :: Ord k => [(k, v)] -> [(k, [v])] groupSortOn :: Ord a => (k -> a) -> [(k, v)] -> [(k, [v])] nubOn :: Eq b => (a -> b) -> [a] -> [a] groupOn :: Eq b => (a -> b) -> [a] -> [[a]] sortOn :: Ord b => (a -> b) -> [a] -> [a] chop :: ([a] -> (b, [a])) -> [a] -> [b] for :: [a] -> (a -> b) -> [b] rep :: Eq a => a -> a -> a -> a reps :: Eq a => a -> a -> [a] -> [a] disjoint :: Eq a => [a] -> [a] -> Bool distinct :: Eq a => [a] -> Bool dropEnd :: Int -> [a] -> [a] takeEnd :: Int -> [a] -> [a] breakEnd :: (a -> Bool) -> [a] -> ([a], [a]) spanEnd :: (a -> Bool) -> [a] -> ([a], [a]) -- | The dropWhileEnd function drops the largest suffix of a list in -- which the given predicate holds for all elements. For example: -- --
-- dropWhileEnd isSpace "foo\n" == "foo"
-- dropWhileEnd isSpace "foo bar" == "foo bar"
-- dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined
--
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
takeWhileEnd :: (a -> Bool) -> [a] -> [a]
-- | Return the prefix of the second string if its suffix matches the
-- entire first string.
--
-- Examples:
--
-- -- stripSuffix "bar" "foobar" == Just "foo" -- stripSuffix "" "baz" == Just "baz" -- stripSuffix "foo" "quux" == Nothing --stripSuffix :: Eq a => [a] -> [a] -> Maybe [a] concatUnzip :: [([a], [b])] -> ([a], [b]) merge :: Ord a => [a] -> [a] -> [a] mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] replace :: String -> String -> String -> String wordsBy :: (a -> Bool) -> [a] -> [[a]] linesBy :: (a -> Bool) -> [a] -> [[a]] firstJust :: (a -> Maybe b) -> [a] -> Maybe b -- | Find the first instance of needle in haystack. The -- first element of the returned tuple is the prefix of haystack -- before needle is matched. The second is the remainder of -- haystack, starting with the match. -- -- Examples: -- --
-- breakOn "::" "a::b::c" == ("a", "::b::c")
-- breakOn "/" "foobar" == ("foobar", "")
--
--
-- Laws:
--
-- -- \needle haystack -> let (prefix,match) = breakOn needle haystack in prefix ++ match == haystack --breakOn :: Eq a => [a] -> [a] -> ([a], [a]) -- | Similar to breakOn, but searches from the end of the string. -- -- The first element of the returned tuple is the prefix of -- haystack up to and including the last match of -- needle. The second is the remainder of haystack, -- following the match. -- --
-- breakOnEnd "::" "a::b::c" == ("a::b::", "c")
--
breakOnEnd :: Eq a => [a] -> [a] -> ([a], [a])
-- | Break a list into pieces separated by the first list argument,
-- consuming the delimiter. An empty delimiter is invalid, and will cause
-- an error to be raised.
--
-- Examples:
--
-- -- splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"] -- splitOn "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""] -- splitOn "x" "x" == ["",""] -- splitOn "x" "" == [""] ---- -- and -- --
-- \s x -> s /= "" ==> intercalate s (splitOn s x) == x -- \c x -> splitOn [c] x == split (==c) x --splitOn :: Eq a => [a] -> [a] -> [[a]] -- | Splits a list into components delimited by separators, where the -- predicate returns True for a separator element. The resulting -- components do not contain the separators. Two adjacent separators -- result in an empty component in the output. eg. -- --
-- split (=='a') "aabbaca" == ["","","bb","c",""] -- split (=='a') "" == [""] --split :: (a -> Bool) -> [a] -> [[a]] chunksOf :: Int -> [a] -> [[a]] dupe :: a -> (a, a) fst3 :: (a, b, c) -> a snd3 :: (a, b, c) -> b thd3 :: (a, b, c) -> c concat2 :: [([a], [b])] -> ([a], [b]) concat3 :: [([a], [b], [c])] -> ([a], [b], [c]) showDP :: RealFloat a => Int -> a -> String intToDouble :: Int -> Double intToFloat :: Int -> Float floatToDouble :: Float -> Double doubleToFloat :: Double -> Float withCurrentDirectory :: FilePath -> IO a -> IO a getDirectoryContentsRecursive :: FilePath -> IO [FilePath] -- | Returns the absolute pathname of the current executable. -- -- Note that for scripts and interactive sessions, this is the path to -- the interpreter (e.g. ghci.) getExecutablePath :: IO FilePath -- | Return the value of the environment variable var, or -- Nothing if there is no such value. -- -- For POSIX users, this is equivalent to getEnv. lookupEnv :: String -> IO (Maybe String) isWindows :: Bool getProcessorCount :: IO Int readFileEncoding :: TextEncoding -> FilePath -> IO String readFileUTF8 :: FilePath -> IO String readFileBinary :: FilePath -> IO String readFile' :: FilePath -> IO String readFileEncoding' :: TextEncoding -> FilePath -> IO String readFileUTF8' :: FilePath -> IO String readFileBinary' :: FilePath -> IO String writeFileEncoding :: TextEncoding -> FilePath -> String -> IO () writeFileUTF8 :: FilePath -> String -> IO () writeFileBinary :: FilePath -> String -> IO () withTempFile :: (FilePath -> IO a) -> IO a withTempDir :: (FilePath -> IO a) -> IO a captureOutput :: IO () -> IO String withBuffering :: Handle -> BufferMode -> IO a -> IO a sleep :: Double -> IO () subtractTime :: UTCTime -> UTCTime -> Double showTime :: Double -> String -- | Call once at the start, then call repeatedly to get Time values out offsetTime :: IO (IO Double) -- | Like offsetTime, but results will never decrease (though they may stay -- the same) offsetTimeIncrease :: IO (IO Double) duration :: IO a -> IO (Double, a)