-- 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 simple additions, filling out missing functionality. A -- few functions are available in later versions of GHC, but this package -- makes them available back to GHC 7.2. -- -- The module Extra documents all functions provided by this -- library. Modules such as Data.List.Extra provide extra -- functions over Data.List and also reexport Data.List. -- Users are recommended to replace Data.List imports with -- Data.List.Extra if they need the extra functionality. @package extra @version 0.3 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 -- | Show a number to a number of decimal places. -- --
-- showDP 4 pi == "3.1416" -- showDP 0 pi == "3" -- showDP 2 3 == "3.00" --showDP :: RealFloat a => Int -> a -> String -- | Specialised numeric conversion. intToDouble :: Int -> Double -- | Specialised numeric conversion. intToFloat :: Int -> Float -- | Specialised numeric conversion. floatToDouble :: Float -> Double -- | Specialised numeric conversion. doubleToFloat :: Double -> Float module System.Time.Extra type Seconds = Double sleep :: Seconds -> IO () subtractTime :: UTCTime -> UTCTime -> Seconds -- | Show a number of seconds, typically a duration, in a suitable manner -- with responable precision for a human. -- --
-- showDuration 3.435 == "3.44s" -- showDuration 623.8 == "10m24s" -- showDuration 62003.8 == "17h13m" -- showDuration 1e8 == "27777h47m" --showDuration :: Seconds -> String -- | Call once at the start, then call repeatedly to get Time values out offsetTime :: IO (IO Seconds) -- | Like offsetTime, but results will never decrease (though they may stay -- the same) offsetTimeIncrease :: IO (IO Seconds) duration :: IO a -> IO (Seconds, a) -- | Extra functions for working with tuples. Some of these functions are -- available in the Control.Arrow module, but here are available -- specialised to pairs. module Data.Tuple.Extra -- | Update the first component of a pair. first :: (a -> a') -> (a, b) -> (a', b) -- | Update the second component of a pair. second :: (b -> b') -> (a, b) -> (a, b') (***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') (&&&) :: (a -> b) -> (a -> c) -> a -> (b, c) dupe :: a -> (a, a) both :: (a -> b) -> (a, a) -> (b, b) fst3 :: (a, b, c) -> a snd3 :: (a, b, c) -> b thd3 :: (a, b, c) -> c -- | Update the first component of a triple. first3 :: (a -> a') -> (a, b, c) -> (a', b, c) -- | Update the second component of a triple. second3 :: (b -> b') -> (a, b, c) -> (a, b', c) -- | Update the third component of a triple. third3 :: (c -> c') -> (a, b, c) -> (a, b, c') dupe3 :: a -> (a, a, a) both3 :: (a -> b) -> (a, a, a) -> (b, b, b) -- | 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 -- | Documentation about lowercase -- --
-- lower "This is A TEST" == "this is a test" -- lower "" == "" --lower :: String -> String upper :: String -> String trim :: String -> String trimStart :: String -> String trimEnd :: 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] -- | Apply some operation repeatedly, producing an element of output and -- the remainder of the list. -- --
-- \xs -> repeatedly (splitAt 3) xs == chunksOf 3 xs -- \xs -> repeatedly word1 (trim xs) == words xs --repeatedly :: ([a] -> (b, [a])) -> [a] -> [b] -- | Flipped version of map. -- --
-- for [1,2,3] (+1) == [2,3,4] --for :: [a] -> (a -> b) -> [b] -- | Are two lists disjoint, with no elements in common. -- --
-- disjoint [1,2,3] [4,5] == True -- disjoint [1,2,3] [4,1] == False --disjoint :: Eq a => [a] -> [a] -> Bool -- | Are all elements the same. -- --
-- allSame [1,1,2] == False -- allSame [1,1,1] == True -- allSame [1] == True -- allSame [] == True --allSame :: Eq a => [a] -> Bool -- | Is there any element which occurs more than once. -- --
-- anySame [1,1,2] == True -- anySame [1,2,3] == False --anySame :: 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]
-- | A version of dropWhileEnd but with different strictness
-- properties. Often outperforms if the list is short or the test is
-- expensive.
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]) concatUnzip3 :: [([a], [b], [c])] -> ([a], [b], [c]) merge :: Ord a => [a] -> [a] -> [a] mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] replace :: Eq a => [a] -> [a] -> [a] -> [a] 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]] -- | Split a list into chunks of a given size. The last chunk may contain -- fewer than n elements. The chunk size must be positive. -- --
-- chunksOf 3 "my test" == ["my ","tes","t"] -- chunksOf 3 "mytest" == ["myt","est"] -- chunksOf 8 "" == [] -- chunksOf 0 "test" == error --chunksOf :: Int -> [a] -> [[a]] module Data.IORef.Extra -- | Strict version of modifyIORef modifyIORef' :: IORef a -> (a -> a) -> IO () -- | Evaluates the value before calling writeIORef 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 () -- | Evaluates the value before calling atomicWriteIORef atomicWriteIORef' :: IORef a -> a -> IO () module Data.Either.Extra isLeft :: Either t t1 -> Bool isRight :: Either t t1 -> Bool -- | The fromLeft function extracts the element out of a Left -- and throws an error if its argument is Right. Much like -- fromJust, using this function in polished code is usually a -- bad idea. fromLeft :: Either l r -> l -- | The fromRight function extracts the element out of a -- Right and throws an error if its argument is Left. Much -- like fromJust, using this function in polished code is -- usually a bad idea. fromRight :: Either l r -> r -- | Pull the value out of an Either where both alternatives have -- the same type. fromEither :: Either a a -> a -- | Extra functions for Control.Exception. These functions provide -- looping, list operations and booleans. If you need a wider selection -- of monad loops and list generalisations, see -- http://hackage.haskell.org/package/monad-loops module Control.Monad.Extra -- | Perform some operation on Just, given the field inside the -- Just. -- --
-- whenJust Nothing print == return () -- whenJust (Just 1) print == print 1 --whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () -- | The identity function which requires the inner argument to be '()'. -- Useful for functions with overloaded return times. -- --
-- \(x :: Maybe ()) -> unit x == x --unit :: m () -> m () -- | A version of partition that works with a monadic predicate. -- --
-- partitionM (Just . even) [1,2,3] == Just ([2], [1,3]) -- partitionM (const Nothing) [1,2,3] == Nothing --partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a]) -- | A version of concatMap that works with a monadic predicate. concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] -- | A version of mapMaybe that works with a monadic predicate. mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] -- | A looping operation, where the predicate returns Left as a seed -- for the next loop or Right to abort the loop. loopM :: Monad m => (a -> m (Either a b)) -> a -> m b -- | Keep running an operation until it becomes False. whileM :: Monad m => m Bool -> m () whenM :: Monad m => m Bool -> m () -> m () unlessM :: Monad m => m Bool -> m () -> 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 -- | Remember that the current directory is a global variable, so calling -- this function multithreaded is almost certain to go wrong. Avoid -- changing the dir if you can. withCurrentDirectory :: FilePath -> IO a -> IO a -- | Find all the files within a directory, including recursively. Looks -- through all folders, including those beginning with .. getDirectoryContentsRecursive :: FilePath -> IO [FilePath] -- | Create a directory with permissions so that only the current user can -- view it. On Windows this function is equivalent to -- createDirectory. createDirectoryPrivate :: String -> IO () -- | Extra functions for Control.Exception. These functions provide -- retrying, showing in the presence of exceptions, and functions to -- catch/ignore exceptions, including monomorphic (no Exception -- context) versions. module Control.Exception.Extra -- | Retry an operation at most N times (N must be positive). -- --
-- retry 1 (print "x") == print "x" -- retry 3 (fail "die") == fail "die" --retry :: Int -> IO a -> IO a -- | Show a value, but if the result contains exceptions, produce -- <Exception>. Defined as stringException . -- show. Particularly useful for printing exceptions to users, -- remembering that exceptions can themselves contain undefined values. showException :: Show e => e -> IO String -- | Fully evaluate an input String. If the String contains embedded -- exceptions it will produce <Exception>. -- --
-- stringException ("test" ++ undefined) == return "test<Exception>"
-- stringException ("test" ++ undefined ++ "hello") == return "test<Exception>"
-- stringException "test" == return "test"
--
stringException :: String -> IO String
-- | Ignore any exceptions thrown by the action.
--
-- -- ignore (print 1) == print 1 -- ignore (fail "die") == return () --ignore :: IO () -> IO () -- | A version of catch without the Exception context, -- restricted to SomeException, so catches all exceptions. catch_ :: IO a -> (SomeException -> IO a) -> IO a -- | Like catch_ but for handle handle_ :: (SomeException -> IO a) -> IO a -> IO a -- | Like catch_ but for try try_ :: IO a -> IO (Either SomeException a) -- | Like catch_ but for catchJust catchJust_ :: (SomeException -> Maybe b) -> IO a -> (b -> IO a) -> IO a -- | Like catch_ but for handleJust handleJust_ :: (SomeException -> Maybe b) -> (b -> IO a) -> IO a -> IO a -- | Like catch_ but for tryJust tryJust_ :: (SomeException -> Maybe b) -> IO a -> IO (Either b a) -- | Catch an exception if the predicate passes, then call the handler with -- the original exception. As an example: -- --
-- > readFileExists x == catchBool isDoesNotExistError (readFile "myfile") (const $ return "") --catchBool :: Exception e => (e -> Bool) -> IO a -> (e -> IO a) -> IO a -- | Like catchBool but for handle. handleBool :: Exception e => (e -> Bool) -> (e -> IO a) -> IO a -> IO a -- | Like catchBool but for try. 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 newTempFile :: (IO FilePath, FilePath -> IO ()) newTempDir :: (IO FilePath, FilePath -> IO ()) -- | Capture the stdout and stderr of a computation. -- --
-- captureOutput (print 1) == return ("1\n",())
--
captureOutput :: IO a -> IO (String, a)
withBuffering :: Handle -> BufferMode -> IO a -> IO a
module System.Process.Extra
system_ :: String -> IO ()
systemOutput :: String -> IO (ExitCode, String)
systemOutput_ :: String -> IO String
-- | Extra functions for Control.Concurrent. These functions
-- manipulate the number of capabilities and new types of lock.
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
-- | Set the number of Haskell threads that can run truly simultaneously
-- (on separate physical processors) at any given time. The number passed
-- to forkOn is interpreted modulo this value. The initial value
-- is given by the +RTS -N runtime flag.
--
-- This is also the number of threads that will participate in parallel
-- garbage collection. It is strongly recommended that the number of
-- capabilities is not set larger than the number of physical processor
-- cores, and it may often be beneficial to leave one or more cores free
-- to avoid contention with other processes in the machine.
setNumCapabilities :: Int -> IO ()
-- | fork a thread and call the supplied function when the thread is about
-- to terminate, with an exception or a returned value. The function is
-- called with asynchronous exceptions masked.
--
-- -- forkFinally action and_then = -- mask $ \restore -> -- forkIO $ try (restore action) >>= and_then ---- -- This function is useful for informing the parent when a child -- terminates, for example. forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId -- | Like an MVar, but has no value data Lock newLock :: IO Lock withLock :: Lock -> IO a -> IO a withLockTry :: Lock -> IO a -> IO (Maybe a) -- | Like an MVar, but must always be full data Var a newVar :: a -> IO (Var a) readVar :: Var a -> IO a modifyVar :: Var a -> (a -> IO (a, b)) -> IO b modifyVar_ :: Var a -> (a -> IO a) -> IO () withVar :: Var a -> (a -> IO b) -> IO b -- | Starts out empty, then is filled exactly once data Barrier a newBarrier :: IO (Barrier a) signalBarrier :: Barrier a -> a -> IO () waitBarrier :: Barrier a -> IO a waitBarrierMaybe :: Barrier a -> IO (Maybe a) -- | This module documents all the functions available in this package. -- -- Most users should import the specific modules (e.g. -- Data.List.Extra), which also reexport their -- non-Extra modules (e.g. Data.List). 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 -- | Set the number of Haskell threads that can run truly simultaneously -- (on separate physical processors) at any given time. The number passed -- to forkOn is interpreted modulo this value. The initial value -- is given by the +RTS -N runtime flag. -- -- This is also the number of threads that will participate in parallel -- garbage collection. It is strongly recommended that the number of -- capabilities is not set larger than the number of physical processor -- cores, and it may often be beneficial to leave one or more cores free -- to avoid contention with other processes in the machine. setNumCapabilities :: Int -> IO () -- | fork a thread and call the supplied function when the thread is about -- to terminate, with an exception or a returned value. The function is -- called with asynchronous exceptions masked. -- --
-- forkFinally action and_then = -- mask $ \restore -> -- forkIO $ try (restore action) >>= and_then ---- -- This function is useful for informing the parent when a child -- terminates, for example. forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId -- | Like an MVar, but has no value data Lock newLock :: IO Lock withLock :: Lock -> IO a -> IO a withLockTry :: Lock -> IO a -> IO (Maybe a) -- | Like an MVar, but must always be full data Var a newVar :: a -> IO (Var a) readVar :: Var a -> IO a modifyVar :: Var a -> (a -> IO (a, b)) -> IO b modifyVar_ :: Var a -> (a -> IO a) -> IO () withVar :: Var a -> (a -> IO b) -> IO b -- | Starts out empty, then is filled exactly once data Barrier a newBarrier :: IO (Barrier a) signalBarrier :: Barrier a -> a -> IO () waitBarrier :: Barrier a -> IO a waitBarrierMaybe :: Barrier a -> IO (Maybe a) -- | Retry an operation at most N times (N must be positive). -- --
-- retry 1 (print "x") == print "x" -- retry 3 (fail "die") == fail "die" --retry :: Int -> IO a -> IO a -- | Show a value, but if the result contains exceptions, produce -- <Exception>. Defined as stringException . -- show. Particularly useful for printing exceptions to users, -- remembering that exceptions can themselves contain undefined values. showException :: Show e => e -> IO String -- | Fully evaluate an input String. If the String contains embedded -- exceptions it will produce <Exception>. -- --
-- stringException ("test" ++ undefined) == return "test<Exception>"
-- stringException ("test" ++ undefined ++ "hello") == return "test<Exception>"
-- stringException "test" == return "test"
--
stringException :: String -> IO String
-- | Ignore any exceptions thrown by the action.
--
-- -- ignore (print 1) == print 1 -- ignore (fail "die") == return () --ignore :: IO () -> IO () -- | A version of catch without the Exception context, -- restricted to SomeException, so catches all exceptions. catch_ :: IO a -> (SomeException -> IO a) -> IO a -- | Like catch_ but for handle handle_ :: (SomeException -> IO a) -> IO a -> IO a -- | Like catch_ but for try try_ :: IO a -> IO (Either SomeException a) -- | Like catch_ but for catchJust catchJust_ :: (SomeException -> Maybe b) -> IO a -> (b -> IO a) -> IO a -- | Like catch_ but for handleJust handleJust_ :: (SomeException -> Maybe b) -> (b -> IO a) -> IO a -> IO a -- | Like catch_ but for tryJust tryJust_ :: (SomeException -> Maybe b) -> IO a -> IO (Either b a) -- | Catch an exception if the predicate passes, then call the handler with -- the original exception. As an example: -- --
-- > readFileExists x == catchBool isDoesNotExistError (readFile "myfile") (const $ return "") --catchBool :: Exception e => (e -> Bool) -> IO a -> (e -> IO a) -> IO a -- | Like catchBool but for handle. handleBool :: Exception e => (e -> Bool) -> (e -> IO a) -> IO a -> IO a -- | Like catchBool but for try. tryBool :: Exception e => (e -> Bool) -> IO a -> IO (Either e a) -- | Perform some operation on Just, given the field inside the -- Just. -- --
-- whenJust Nothing print == return () -- whenJust (Just 1) print == print 1 --whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () -- | The identity function which requires the inner argument to be '()'. -- Useful for functions with overloaded return times. -- --
-- \(x :: Maybe ()) -> unit x == x --unit :: m () -> m () -- | A version of partition that works with a monadic predicate. -- --
-- partitionM (Just . even) [1,2,3] == Just ([2], [1,3]) -- partitionM (const Nothing) [1,2,3] == Nothing --partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a]) -- | A version of concatMap that works with a monadic predicate. concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] -- | A version of mapMaybe that works with a monadic predicate. mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] -- | A looping operation, where the predicate returns Left as a seed -- for the next loop or Right to abort the loop. loopM :: Monad m => (a -> m (Either a b)) -> a -> m b -- | Keep running an operation until it becomes False. whileM :: Monad m => m Bool -> m () whenM :: Monad m => m Bool -> m () -> m () unlessM :: Monad m => m Bool -> m () -> 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 -- | The fromLeft function extracts the element out of a Left -- and throws an error if its argument is Right. Much like -- fromJust, using this function in polished code is usually a -- bad idea. fromLeft :: Either l r -> l -- | The fromRight function extracts the element out of a -- Right and throws an error if its argument is Left. Much -- like fromJust, using this function in polished code is -- usually a bad idea. fromRight :: Either l r -> r -- | Pull the value out of an Either where both alternatives have -- the same type. fromEither :: Either a a -> a -- | Strict version of modifyIORef modifyIORef' :: IORef a -> (a -> a) -> IO () -- | Evaluates the value before calling writeIORef 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 () -- | Evaluates the value before calling atomicWriteIORef atomicWriteIORef' :: IORef a -> a -> IO () -- | Documentation about lowercase -- --
-- lower "This is A TEST" == "this is a test" -- lower "" == "" --lower :: String -> String upper :: String -> String trim :: String -> String trimStart :: String -> String trimEnd :: 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] -- | Apply some operation repeatedly, producing an element of output and -- the remainder of the list. -- --
-- \xs -> repeatedly (splitAt 3) xs == chunksOf 3 xs -- \xs -> repeatedly word1 (trim xs) == words xs --repeatedly :: ([a] -> (b, [a])) -> [a] -> [b] -- | Flipped version of map. -- --
-- for [1,2,3] (+1) == [2,3,4] --for :: [a] -> (a -> b) -> [b] -- | Are two lists disjoint, with no elements in common. -- --
-- disjoint [1,2,3] [4,5] == True -- disjoint [1,2,3] [4,1] == False --disjoint :: Eq a => [a] -> [a] -> Bool -- | Are all elements the same. -- --
-- allSame [1,1,2] == False -- allSame [1,1,1] == True -- allSame [1] == True -- allSame [] == True --allSame :: Eq a => [a] -> Bool -- | Is there any element which occurs more than once. -- --
-- anySame [1,1,2] == True -- anySame [1,2,3] == False --anySame :: 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]
-- | A version of dropWhileEnd but with different strictness
-- properties. Often outperforms if the list is short or the test is
-- expensive.
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]) concatUnzip3 :: [([a], [b], [c])] -> ([a], [b], [c]) merge :: Ord a => [a] -> [a] -> [a] mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] replace :: Eq a => [a] -> [a] -> [a] -> [a] 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]] -- | Split a list into chunks of a given size. The last chunk may contain -- fewer than n elements. The chunk size must be positive. -- --
-- chunksOf 3 "my test" == ["my ","tes","t"] -- chunksOf 3 "mytest" == ["myt","est"] -- chunksOf 8 "" == [] -- chunksOf 0 "test" == error --chunksOf :: Int -> [a] -> [[a]] -- | Update the first component of a pair. first :: (a -> a') -> (a, b) -> (a', b) -- | Update the second component of a pair. second :: (b -> b') -> (a, b) -> (a, b') (***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') (&&&) :: (a -> b) -> (a -> c) -> a -> (b, c) dupe :: a -> (a, a) both :: (a -> b) -> (a, a) -> (b, b) fst3 :: (a, b, c) -> a snd3 :: (a, b, c) -> b thd3 :: (a, b, c) -> c -- | Update the first component of a triple. first3 :: (a -> a') -> (a, b, c) -> (a', b, c) -- | Update the second component of a triple. second3 :: (b -> b') -> (a, b, c) -> (a, b', c) -- | Update the third component of a triple. third3 :: (c -> c') -> (a, b, c) -> (a, b, c') dupe3 :: a -> (a, a, a) both3 :: (a -> b) -> (a, a, a) -> (b, b, b) -- | Show a number to a number of decimal places. -- --
-- showDP 4 pi == "3.1416" -- showDP 0 pi == "3" -- showDP 2 3 == "3.00" --showDP :: RealFloat a => Int -> a -> String -- | Specialised numeric conversion. intToDouble :: Int -> Double -- | Specialised numeric conversion. intToFloat :: Int -> Float -- | Specialised numeric conversion. floatToDouble :: Float -> Double -- | Specialised numeric conversion. doubleToFloat :: Double -> Float -- | Remember that the current directory is a global variable, so calling -- this function multithreaded is almost certain to go wrong. Avoid -- changing the dir if you can. withCurrentDirectory :: FilePath -> IO a -> IO a -- | Find all the files within a directory, including recursively. Looks -- through all folders, including those beginning with .. getDirectoryContentsRecursive :: FilePath -> IO [FilePath] -- | Create a directory with permissions so that only the current user can -- view it. On Windows this function is equivalent to -- createDirectory. createDirectoryPrivate :: String -> IO () -- | 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 newTempFile :: (IO FilePath, FilePath -> IO ()) newTempDir :: (IO FilePath, FilePath -> IO ()) -- | Capture the stdout and stderr of a computation. -- --
-- captureOutput (print 1) == return ("1\n",())
--
captureOutput :: IO a -> IO (String, a)
withBuffering :: Handle -> BufferMode -> IO a -> IO a
system_ :: String -> IO ()
systemOutput :: String -> IO (ExitCode, String)
systemOutput_ :: String -> IO String
type Seconds = Double
sleep :: Seconds -> IO ()
subtractTime :: UTCTime -> UTCTime -> Seconds
-- | Show a number of seconds, typically a duration, in a suitable manner
-- with responable precision for a human.
--
-- -- showDuration 3.435 == "3.44s" -- showDuration 623.8 == "10m24s" -- showDuration 62003.8 == "17h13m" -- showDuration 1e8 == "27777h47m" --showDuration :: Seconds -> String -- | Call once at the start, then call repeatedly to get Time values out offsetTime :: IO (IO Seconds) -- | Like offsetTime, but results will never decrease (though they may stay -- the same) offsetTimeIncrease :: IO (IO Seconds) duration :: IO a -> IO (Seconds, a)