structural-typing.assist.defaults
User-visible default behaviors.
Much of this is gathered into the catchall structural-typing.types
namespace.
default-error-handler
This error handler takes the output of type checking (a sequence of oopsies) and prints each one’s explanation to standard output. It returns nil
, allowing constructs like this:
(some-> (type/built-like :Patient p)
(assoc :handled true)
...)
default-predicate-explainer
(default-predicate-explainer {:keys [predicate-string leaf-value], :as expred})
Converts an oopsie into a string of the form “%s should be %s
; it is %s
”.
default-success-handler
The default success handler just returns the original candidate structure passed to built-like
.
throwing-error-handler
(throwing-error-handler oopsies)
In contrast to the default error handler, this one throws a java.lang.Exception
whose message is the concatenation of the explanations of the oopsies.
To make all type mismatches throw failures, do this:
(global-type/on-error! type/throwing-error-handler) ; for the global type repo
(type/replace-error-handler type-repo type/throwing-error-handler) ; local repo