highlight-1.0.0.2: Command line tool for highlighting parts of files matching a regex.
Safe HaskellNone
LanguageHaskell2010

Highlight.Util

Synopsis

Documentation

convertStringToRawByteString :: MonadIO m => String -> m ByteString Source #

Convert a String to a ByteString with the encoding for the current locale.

>>> convertStringToRawByteString "hello"
"hello"

openFilePathForReading :: MonadIO m => FilePath -> m (Either IOException Handle) Source #

Open a FilePath in ReadMode.

On success, return a Right Handle:

>>> openFilePathForReading "README.md"
Right {handle: README.md}

On error, return a Left IOException:

>>> openFilePathForReading "thisfiledoesntexist"
Left thisfiledoesntexist: openBinaryFile: does not exist ...

combineApplicatives :: (Applicative f, Semigroup a) => f a -> f a -> f a Source #

Combine values in two Applicatives with <>.

>>> combineApplicatives (Just "hello") (Just " world")
Just "hello world"
>>> combineApplicatives (Just "hello") Nothing
Nothing

closeHandleIfEOFOrThrow :: MonadIO m => Handle -> IOException -> m () Source #

Handle an IOException that occurs when reading from a Handle. Check if the IOException is an EOF exception (hIsEOF). If so, then just close the Handle. Otherwise, throw the IOException that is passed in.

die Source #

Arguments

:: Int

exit code

-> String

error message to print to console

-> IO a 

Call exitWith with ExitFailure

>>> die 10 "message"
ERROR: message
*** Exception: ExitFailure 10

whenNonNull :: Monad m => [a] -> m () -> m () Source #

Perform an action when a list is non-null.

>>> whenNonNull [1,2,3] $ putStrLn "hello"
hello
>>> whenNonNull [] $ putStrLn "bye"

modify' :: MonadState s m => (s -> s) -> m () Source #

A variant of modify in which the computation is strict in the new state.

This is used because modify' is not available in the tranformers-0.3.0.0 package.