universum-1.6.0: Custom prelude used in Serokell

Safe HaskellSafe
LanguageHaskell2010

Universum.Lifted.File

Description

Lifted versions of functions working with files and common IO. All functions are specialized to Text.

Synopsis

Documentation

appendFile :: MonadIO m => FilePath -> Text -> m () Source #

Lifted version of appendFile.

getLine :: MonadIO m => m Text Source #

Lifted version of getLine.

readFile :: MonadIO m => FilePath -> m Text Source #

Lifted version of readFile.

writeFile :: MonadIO m => FilePath -> Text -> m () Source #

Lifted version of writeFile.

withFile :: (MonadIO m, MonadMask m) => FilePath -> IOMode -> (Handle -> m a) -> m a Source #

Opens a file, manipulates it with the provided function and closes the handle before returning. The Handle can be written to using the hPutStr and hPutStrLn functions.

withFile is essentially the bracket pattern, specialized to files. This should be preferred over openFile + hClose as it properly deals with (asynchronous) exceptions. In cases where withFile is insufficient, for instance because the it is not statically known when manipulating the Handle has finished, one should consider other safe paradigms for resource usage, such as the ResourceT transformer from the resourcet package, before resorting to openFile and hClose.

openFile :: MonadIO m => FilePath -> IOMode -> m Handle Source #

Lifted version of openFile.

See also withFile for more information.

hClose :: MonadIO m => Handle -> m () Source #

Close a file handle

See also withFile for more information.