drasil-utils-0.1.1.0: A framework for code and document generation for scientific software - Utils SubPackage
Safe HaskellSafe-Inferred
LanguageHaskell2010

Utils.Drasil

Description

Gather Drasil's utility functions and re-export for easy use.

Synopsis

Directory

createDirIfMissing :: Bool -> FilePath -> IO () Source #

Creates a directory if it does not already exist (optionally with all missing parent directories).

Implementation uses doesPathExist to check if the directory exists rather than createDirectoryIfMissing True, which would create the directory regardless of whether it exists or not, potentially leading to an error that appears in `make debug` logs.

Documents

blank :: Doc Source #

Creates a blank document with no text.

indent :: Doc -> Doc Source #

Indents a document (by 4 spaces).

indentList :: [Doc] -> Doc Source #

Indents a list of Docs and combines into one Doc.

filterEmpty :: [Doc] -> [Doc] Source #

Filter blank Docs from a list.

listToDoc :: [String] -> Doc Source #

Merge a list of Strings into a Doc format:

e.g., `listToDoc [a,b,c,...] ~= a, b, c, ...`

type Separator = Doc Source #

Separates document sections.

Language

capitalize :: String -> String Source #

String capitalization.

stringList :: [String] -> String Source #

Comma separated list with "and" before final item.

Lists

From Utils.Drasil.Lists. General functions involving lists.

atLeast2 :: [a] -> Bool Source #

Check if list has at least 2 elements.

replaceAll :: Eq a => [a] -> a -> [a] -> [a] Source #

Replaces all elements of a target list that belong to a provided "bad" input list.

subsetOf :: Eq a => [a] -> [a] -> Bool Source #

Checks if the first set is a subset of the second.

nubSort :: Ord a => [a] -> [a] Source #

Sort a list, removing all duplicates

weave :: [[a]] -> [a] Source #

Interweaves two lists together [[a,b,c],[d,e,f]] -> [a,d,b,e,c,f].

foldle :: (a -> a -> a) -> (a -> a -> a) -> a -> [a] -> a Source #

Fold helper function that applies f to all but the last element, applies g to last element and the accumulator.

foldle1 :: (a -> a -> a) -> (a -> a -> a) -> [a] -> a Source #

Fold helper function that applies f to all but last element, applies g to last element and accumulator without starting value, does not work for empty list.

toColumn :: [a] -> [[a]] Source #

Convert "row" of elements into "column" of elements.

mkTable :: [a -> b] -> [a] -> [[b]] Source #

Create a table body (not including header row) by applying the given functions to the column elements of the table rows (in order). The first argument is a list of functions to be applied (one per column). This essentially creates the rows. The second argument is a list of elements apply the functions to.

For example, mkTable [id, *5] [1,2,3] should produce a table:

| 1 |  5 |
| 2 | 10 |
| 3 | 15 |

Maps

invert :: Ord v => Map k [v] -> Map v [k] Source #

Strings

toPlainName :: String -> String Source #

Replace occurences of special characters (",~`-=!#$%^&*+[]\;'/|"<>? ") with underscores ("_"@).

TODO: This can probably become a bit more comprehensive, anything other than a-z, A-Z, or 0-9 could probably be replaced.

repUnd :: String -> String Source #

Replace underscores in a string with periods (.).

CSV

makeCSV :: [[String]] -> Doc Source #

Creates a CSV file as a Doc from a String matrix.