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):
const composeComparators = operation => (arg? => Either<Array<Error>, result>)
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.
const composeOperators = operation => (arg? => Either<Array<Error>, result>)
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.
const composeValidator = operation => (arg? => Either<Array<Error>, result>)
Conditionals
The composeConditional
function wraps the composeComparators function, but returns a
plain Boolean value, true or false.
const composeConditional = operation => (arg? => Boolean)
This makes it easy to use the composeComparators function for
conditional display by returning a plain Boolean instead of an Either.