ord -package:sbv -package:leancheck -package:cabal-install-solver -package:invertible package:hledger
The
Ord class is used for totally ordered datatypes.
Instances of
Ord can be derived for any user-defined datatype
whose constituent types are in
Ord. The declared order of the
constructors in the data declaration determines the ordering in
derived
Ord instances. The
Ordering datatype allows a
single comparison to determine the precise ordering of two objects.
Ord, as defined by the Haskell report, implements a total order
and has the following properties:
- Comparability x <= y || y <= x =
True
- Transitivity if x <= y && y <=
z = True, then x <= z = True
- Reflexivity x <= x = True
- Antisymmetry if x <= y && y <=
x = True, then x == y = True
The following operator interactions are expected to hold:
- x >= y = y <= x
- x < y = x <= y && x /= y
- x > y = y < x
- x < y = compare x y == LT
- x > y = compare x y == GT
- x == y = compare x y == EQ
- min x y == if x <= y then x else y = True
- max x y == if x >= y then x else y = True
Note that (7.) and (8.) do
not require
min and
max to return either of their arguments. The result is merely
required to
equal one of the arguments in terms of
(==).
Minimal complete definition: either
compare or
<=.
Using
compare can be more efficient for complex types.
Extract ExceptT to the IO monad, failing with an error message if
necessary.
A more expressive Ord, used for amt: queries. The Abs* variants
compare with the absolute value of a number, ignoring sign.
Custom error data for hledger parsers. Specialised for a
Text
parse stream. ReparseableTextParseErrorData ?
the order in which this account was declared, relative to other
account declarations, during parsing (1..)
Debug log the ordering of a journal's account declarations (at debug
level 5+).
For a MixedAmount, an optional order in which to display the
commodities. Also, causes 0s to be generated for any commodities which
are not present (important for tabular reports).
Get a posting's primary or secondary date, as specified.
unwords joins words with separating spaces (U+0020 SPACE).
>>> unwords ["Lorem", "ipsum", "dolor"]
"Lorem ipsum dolor"
unwords is neither left nor right inverse of
words:
>>> words (unwords [" "])
[]
>>> unwords (words "foo\nbar")
"foo bar"
Quote-aware version of unwords - single-quote strings which contain
whitespace
words breaks a string up into a list of words, which were
delimited by white space (as defined by
isSpace). This function
trims any white spaces at the beginning and at the end.
>>> words "Lorem ipsum\ndolor"
["Lorem","ipsum","dolor"]
>>> words " foo bar "
["foo","bar"]
Quote-aware version of words - don't split on spaces which are inside
quotes. NB correctly handles "a'b" but not "'a'". Can raise
an error if parsing fails.
Quote-and-prefix-aware version of words - don't split on spaces which
are inside quotes, including quotes which may have one of the
specified prefixes in front, and maybe an additional not: prefix in
front of that.