hledger-lib-1.41: A library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Utils

Contents

- Functions
- Lists
- Trees
- Tuples
- Misc
- Other
- Tests

Description

Utilities used throughout hledger, or needed low in the module hierarchy. These are the bottom of hledger's module graph.

Synopsis

- applyN :: Int -> (a -> a) -> a -> a
- mapM' :: Monad f => (a -> f b) -> [a] -> f [b]
- sequence' :: Monad f => [f a] -> f [a]
- curry2 :: ((a, b) -> c) -> a -> b -> c
- uncurry2 :: (a -> b -> c) -> (a, b) -> c
- curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
- uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
- curry4 :: ((a, b, c, d) -> e) -> a -> b -> c -> d -> e
- uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
- maximum' :: Integral a => [a] -> a
- maximumStrict :: Ord a => [a] -> a
- minimumStrict :: Ord a => [a] -> a
- splitAtElement :: Eq a => a -> [a] -> [[a]]
- sumStrict :: Num a => [a] -> a
- treeLeaves :: Tree a -> [a]
- first3 :: (a, b, c) -> a
- second3 :: (a, b, c) -> b
- third3 :: (a, b, c) -> c
- first4 :: (a, b, c, d) -> a
- second4 :: (a, b, c, d) -> b
- third4 :: (a, b, c, d) -> c
- fourth4 :: (a, b, c, d) -> d
- first5 :: (a, b, c, d, e) -> a
- second5 :: (a, b, c, d, e) -> b
- third5 :: (a, b, c, d, e) -> c
- fourth5 :: (a, b, c, d, e) -> d
- fifth5 :: (a, b, c, d, e) -> e
- first6 :: (a, b, c, d, e, f) -> a
- second6 :: (a, b, c, d, e, f) -> b
- third6 :: (a, b, c, d, e, f) -> c
- fourth6 :: (a, b, c, d, e, f) -> d
- fifth6 :: (a, b, c, d, e, f) -> e
- sixth6 :: (a, b, c, d, e, f) -> f
- multicol :: Int -> [String] -> String
- numDigitsInt :: Integral a => Int -> a
- numDigitsInteger :: Integer -> Int
- makeHledgerClassyLenses :: Name -> DecsQ
- module Hledger.Utils.Debug
- module Hledger.Utils.Parse
- module Hledger.Utils.IO
- module Hledger.Utils.Regex
- module Hledger.Utils.String
- module Hledger.Utils.Text
- tests_Utils :: TestTree
- module Hledger.Utils.Test

# Functions

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

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

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

Like mapM but uses sequence'.

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

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.

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

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

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

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

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

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

# Lists

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

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

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

Strict version of maximum that doesn’t leak space

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

Strict version of minimum that doesn’t leak space

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

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

Strict version of sum that doesn’t leak space

# Trees

treeLeaves :: Tree a -> [a] #

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

# Tuples

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Misc

multicol :: Int -> [String] -> String #

Convert a list of strings to a multi-line multi-column list fitting within the given width. Not wide character aware.

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

Find the number of digits of an `Int`.

numDigitsInteger :: Integer -> Int #

Find the number of digits of an Integer. The integer should not have more digits than an Int can count. This is probably inefficient.

makeHledgerClassyLenses :: Name -> DecsQ #

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

# Other

module Hledger.Utils.Debug

module Hledger.Utils.Parse

module Hledger.Utils.IO

module Hledger.Utils.Regex

module Hledger.Utils.String

module Hledger.Utils.Text

# Tests

tests_Utils :: TestTree #

module Hledger.Utils.Test