libro-backend-0.1.0.0: Restful data backend of the LiBro app
Safe HaskellSafe-Inferred
LanguageHaskell2010

LiBro.Util

Description

Helper functions and types that can be useful in more than one place.

Synopsis

Tree building

type ParentList a = [(a, Maybe a)] Source #

A Tree/Forest representation as a linear list. All entries point to their parent.

readForest :: Ord a => ParentList a -> Forest a Source #

Reads a forest from a given ParentList, sorting each Nodes children.

Counting monad transformer

type CountingT m = StateT Int m Source #

Simple monad transformer that allows to read an increasing Int.

next :: Monad m => CountingT m Int Source #

Grabs the next Int.

runCountingT :: Monad m => CountingT m a -> Int -> m a Source #

Evaluate the given action with counting from the given initial value.

XLSX as data backend

storeAsXlsx :: (DefaultOrdered a, ToNamedRecord a) => FilePath -> [a] -> IO () Source #

Store a list of (CSV-transformable) data to a XLSX file. CAVEAT: round-trips don't work with unsafe text values. Use LiBro.Data.SafeText.

loadFromXlsx :: FromNamedRecord a => FilePath -> IO (Either String [a]) Source #

Load a list of (CSV-transformable) data from a XLSX file. CAVEAT: round-trips don't work with unsafe text values. Use LiBro.Data.SafeText.

Shady LibreOffice handling

libreOfficeIsRunning :: IO Bool Source #

Tries to report if a LibreOffice instance is already running

spawnLibreOffice :: IO () Source #

Starts LibreOffice in the background. This is useful to speed up conversion.

killLibreOffice :: IO () Source #

Kills LibreOffice with SIGKILL, if it is actually running. See libreOfficeIsRunning.

Other helper functions

guarded :: Alternative f => (a -> Bool) -> a -> f a Source #

Create an Alternative value based on a predicate.