Composers
There are four available compose functions. These compose comparators, conditionals, operators, and validation,
Comparators
Comparators are used for validation and conditional display.
The comparator
operations
are composed into a single function that does the potentially-nested comparison
(with and
and or
):
Examples of comparator operations are IsMoreThan
, IsAfterAlphabetically
, IsBeforeDateTime
, Matches
, and IsDisjointSet
.
If the comparison evaluates to false
, then a Left
is returned with one or more Error
objects explaining which
comparison(s) failed.
If the comparison evaluates to true
, then a Right
is returned
with the value that was tested. See composeComparators
for more detail.
Operators
Operators are used for numerical calculations. Not only can
these operations be nested to any depth, but they can be used to generate the
operand
and/or test
values for use in comparator
operations.
Operators include the JavaScript arithmetic operators
and the Math module operations. Examples: add
,
subtract
,
multiply
,
divide
,
floor
,
mean
, and
root
. See the
full list of operators.
If the operation fails, then a Left
is returned with one or more
Error
objects explaining which comparison(s) failed. If the operations
succeeds, then a Right
is returned containing the calculated value (a number). This result can be
used in other calculations, comparisons, etc.
Validation
The composeValidation
function wraps the composeComparators
function, returning the
same results. In the future, there may be added functionality here.
Conditionals
The composeConditional
function wraps the composeComparators
function, but returns a
plain Boolean value, true
or false
.
This makes it easy to use the composeComparators
function for
conditional display by returning a plain Boolean instead of an Either
.