hledger-lib-1.26.1: A reusable library providing the core functionality of hledger
Safe HaskellNone
LanguageHaskell2010

Hledger.Utils

Description

Standard imports and utilities which are useful everywhere, or needed low in the module hierarchy. This is the bottom of hledger's module graph.

Synopsis

Documentation

first3 :: (a, b, c) -> a Source #

second3 :: (a, b, c) -> b Source #

third3 :: (a, b, c) -> c Source #

first4 :: (a, b, c, d) -> a Source #

second4 :: (a, b, c, d) -> b Source #

third4 :: (a, b, c, d) -> c Source #

fourth4 :: (a, b, c, d) -> d Source #

first5 :: (a, b, c, d, e) -> a Source #

second5 :: (a, b, c, d, e) -> b Source #

third5 :: (a, b, c, d, e) -> c Source #

fourth5 :: (a, b, c, d, e) -> d Source #

fifth5 :: (a, b, c, d, e) -> e Source #

first6 :: (a, b, c, d, e, f) -> a Source #

second6 :: (a, b, c, d, e, f) -> b Source #

third6 :: (a, b, c, d, e, f) -> c Source #

fourth6 :: (a, b, c, d, e, f) -> d Source #

fifth6 :: (a, b, c, d, e, f) -> e Source #

sixth6 :: (a, b, c, d, e, f) -> f Source #

curry2 :: ((a, b) -> c) -> a -> b -> c Source #

uncurry2 :: (a -> b -> c) -> (a, b) -> c Source #

curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d Source #

uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d Source #

curry4 :: ((a, b, c, d) -> e) -> a -> b -> c -> d -> e Source #

uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e Source #

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

treeLeaves :: Show a => Tree a -> [a] Source #

Get the leaves of this tree as a list. The topmost node ("root" in hledger account trees) is not counted as a leaf.

applyN :: Int -> (a -> a) -> a -> a Source #

Apply a function the specified number of times, which should be > 0 (otherwise does nothing). Possibly uses O(n) stack ?

expandPath :: FilePath -> FilePath -> IO FilePath Source #

Convert a possibly relative, possibly tilde-containing file path to an absolute one, given the current directory. ~username is not supported. Leave "-" unchanged. Can raise an error.

expandHomePath :: FilePath -> IO FilePath Source #

Expand user home path indicated by tilde prefix

readFilePortably :: FilePath -> IO Text Source #

Read text from a file, converting any rn line endings to n,, using the system locale's text encoding, ignoring any utf8 BOM prefix (as seen in paypal's 2018 CSV, eg) if that encoding is utf8.

readFileOrStdinPortably :: String -> IO Text Source #

Like readFilePortably, but read from standard input if the path is "-".

maximum' :: Integral a => [a] -> a Source #

Total version of maximum, for integral types, giving 0 for an empty list.

sumStrict :: Num a => [a] -> a Source #

Strict version of sum that doesn’t leak space

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

Strict version of maximum that doesn’t leak space

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

Strict version of minimum that doesn’t leak space

sequence' :: Monad f => [f a] -> f [a] Source #

This is a version of sequence based on difference lists. It is slightly faster but we mostly use it because it uses the heap instead of the stack. This has the advantage that Neil Mitchell’s trick of limiting the stack size to discover space leaks doesn’t show this as a false positive.

mapM' :: Monad f => (a -> f b) -> [a] -> f [b] Source #

Like mapM but uses sequence'.

numDigitsInt :: Integral a => Int -> a Source #

Find the number of digits of an Int.

error' :: String -> a Source #

Simpler alias for errorWithoutStackTrace

usageError :: String -> a Source #

A version of errorWithoutStackTrace that adds a usage hint.

embedFileRelative :: FilePath -> Q Exp Source #

Like embedFile, but takes a path relative to the package directory. Similar to embedFileRelative ?

color :: ColorIntensity -> Color -> String -> String Source #

Wrap a string in ANSI codes to set and reset foreground colour.

bgColor :: ColorIntensity -> Color -> String -> String Source #

Wrap a string in ANSI codes to set and reset background colour.

colorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder Source #

Wrap a WideBuilder in ANSI codes to set and reset foreground colour.

bgColorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder Source #

Wrap a WideBuilder in ANSI codes to set and reset background colour.

makeHledgerClassyLenses :: Name -> DecsQ Source #

Make classy lenses for Hledger options fields. This is intended to be used with BalancingOpts, InputOpt, ReportOpts, ReportSpec, and CliOpts. When run on X, it will create a typeclass named HasX (except for ReportOpts, which will be named HasReportOptsNoUpdate) containing all the lenses for that type. If the field name starts with an underscore, the lens name will be created by stripping the underscore from the front on the name. If the field name ends with an underscore, the field name ends with an underscore, the lens name will be mostly created by stripping the underscore, but a few names for which this would create too many conflicts instead have a second underscore appended. ReportOpts fields for which updating them requires updating the query in ReportSpec are instead names by dropping the trailing underscore and appending NoUpdate to the name, e.g. querystring_ -> querystringNoUpdate.

There are a few reasons for the complicated rules. - We have some legacy field names ending in an underscore (e.g. value_) which we want to temporarily accommodate, before eventually switching to a more modern style (e.g. _rsReportOpts) - Certain fields in ReportOpts need to update the enclosing ReportSpec when they are updated, and it is a common programming error to forget to do this. We append NoUpdate to those lenses which will not update the enclosing field, and reserve the shorter name for manually define lenses (or at least something lens-like) which will update the ReportSpec. cf. the lengthy discussion here and in surrounding comments: https://github.com/simonmichael/hledger/pull/1545#issuecomment-881974554