structural-typing.api.predicates

Functions used to construct predicates that explain themselves, plus some frequently useful predicates of that sort.

Much of this is gathered into the catchall structural-typing.types namespace.

exactly

(exactly x)

Produce a predicate that’s true iff the value it’s applied to is = to x.

( (exactly 5) 4) => false (type! :V5 {:version (exactly 5)})

explain-with

(explain-with explainer predicate)

After the predicate fails, the failure will need to be explained. Arrange for the explainer function to be called with the oopsie that results from the failure.

member

(member coll)

Produce a predicate that’s false when applied to a value not a member of coll. The explainer associated with member prints those colls.

  ( (member [2 3 5 7]) 4) => false
  (type! :small-primes {:n (member [2 3 5 7])})

required-key

False iff a key/path does not exist or has value nil. This is the only predicate that is not considered optional.

should-be

(should-be format-string expected)

show-as

(show-as name predicate)

Associate the given name string with the predicate for use when predicate failures are explained.

  (->> (partial >= 3) (show-as "less than 3"))