structural-typing.assist.predicate-defining

Helpers for defining custom predicates. See structural-typing.preds for examples of use.

compose-predicate

(compose-predicate name pred fmt-fn)

A checker can be any function. But it’s often more useful to “compose” a checker predicate from three parts: its name to be printed (such as "(member [1 2 3])"), a function, and an explainer function that converts an oopsie into a string. This function creates a checker function from those three parts.

Note that expected is formatted as a readable value. So, for example, strings appear in the explanation surrounded by quotes.

The resulting predicate still returns the same values as the second argument (the “underlying” predicate), but it has extra metadata.

should-be

(should-be format-string expected)

The typical explanation string is built from a path, expected value, and leaf value, in that order. The path and leaf value can be gotten from an oopsie. This, then, is shorthand that lets you build an explainer function from just a format string and an expected value.

(should-be "%s should be a member of `%s`; it is `%s`" coll)