Endo API documentation - v0.2.0 / Exports / @endo/common / ident-checker
Module: ident-checker
Table of contents
Type Aliases
Functions
Type Aliases
Checker
Ƭ Checker: (cond
: boolean
, details?
: ses
) => boolean
Internal to a useful pattern for writing checking logic (a "checkFoo" function) that can be used to implement a predicate (an "isFoo" function) or a validator (an "assertFoo" function).
- A predicate ideally only returns
true
orfalse
and rarely throws. - A validator throws an informative diagnostic when the predicate would have returned
false
, and simply returnsundefined
normally when the predicate would have returnedtrue
. - The internal checking function that they share is parameterized by a
Checker
that determines how to proceed with a failure condition. Predicates pass in an identity function as checker. Validators pass inassertChecker
which is a trivial wrapper aroundassert
.
See the various uses for good examples.
Type declaration
▸ (cond
, details?
): boolean
Parameters
Name | Type |
---|---|
cond | boolean |
details? | ses |
Returns
boolean
Defined in
Functions
identChecker
▸ identChecker(cond
, details?
): boolean
In the assertFoo
/isFoo
/checkFoo
pattern, checkFoo
has a check
parameter of type Checker
. assertFoo
calls checkFoo
passes assertChecker
as the check
argument. isFoo
passes identChecker
as the check
argument. identChecker
acts precisely like an identity function, but is typed as a Checker
to indicate its intended use.
Parameters
Name | Type |
---|---|
cond | boolean |
details? | Details |
Returns
boolean