Apply a function the specified number of times, which should be > 0 (otherwise does nothing). Possibly uses O(n) stack ?
Modulehledger-lib-1.52.4GHC2021
Hledger.Utils
Utilities used throughout hledger, or needed low in the module hierarchy. These are the bottom of hledger's module graph.
Synopsis
- value applyN
- value mapM'
- value sequence'
- value curry2
- value uncurry2
- value curry3
- value uncurry3
- value curry4
- value uncurry4
- value divideSafe
- value maximum'
- value maximumStrict
- value minimumStrict
- value splitAtElement
- value sumStrict
- value all1
- value takeUntilFails
- value takeUntilFailsNE
- value treeLeaves
- value first3
- value second3
- value third3
- value first4
- value second4
- value third4
- value fourth4
- value first5
- value second5
- value third5
- value fourth5
- value fifth5
- value first6
- value second6
- value third6
- value fourth6
- value fifth6
- value sixth6
- value multicol
- value numDigitsInt
- value numDigitsInteger
- value makeHledgerClassyLenses
- value tests_Utils
- Packagehledger-lib-1.52.4
- Exports42
- LanguageGHC2021
- LicenceGPL-3.0-or-later
- SourceUtils.hs
Functions
Like mapM but uses sequence'.
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.
Division, returning 0 when the denominator is 0.
Lists
Total version of maximum, for integral types, giving 0 for an empty list.
Strict version of maximum that doesn’t leak space
Strict version of minimum that doesn’t leak space
Strict version of sum that doesn’t leak space
Version of all that fails on an empty list.
Take elements from a list until a predicate fails, and then keep the first failing element as well.
Take elements from a non-empty list until a predicate fails, and then keep the first failing element as well.
Trees
Get the leaves of this tree as a list. The topmost node ("root" in hledger account trees) is not counted as a leaf.
Tuples
Misc
Convert a list of strings to a multi-line multi-column list fitting within the given width. Not wide character aware.
Find the number of digits of an 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.
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
module Hledger.Utils.Test