A predicate is a function that returns a true or false value and their names end with
? by convention.
(string? "am i a string")
clojure.core predicate functions
Using predicate functions as specifications
Predicate functions can be used as un-named specifications to test values conform.
clojure.spec.alpha namespace to access the spec functions.
(require '[clojure.spec.alpha :as spec])
(spec/conform int? 42)
(spec/conform seq? (range 4))
Custom predicate functions
Define custom predicate functions with
fn or the short form
Using an anonymous function
(spec/conform (fn [value] (= value 42)) 42)
When the expression is quite terse, then the short form of an anonymous function is typically used. The
% represents the value passed as an argument.
(spec/conform #(= % 42) 42)