(defn max-length
[max-size]
(s/pred (fn [s] (>= max-size (count s)))
(str "max-length[" max-size "]")))
(s/validate (s/both s/Str (max-length 5)) "hello")
;;=> "hello"
(s/validate (s/both s/Str (max-length 5)) "hello!")
;;=> ExceptionInfo Value does not match schema: (not ("max-length[5]" "hello!"))
(s/validate (s/constrained s/Str (max-length 5)) "hello")
;;=> Not a function: schema.core.Predicate@b79b020b
(defn max-length2
[max-size]
(fn [s] (>= max-size (count s))))
(s/validate (s/constrained s/Str (max-length2 5)) "hello!")
;;=> Value does not match schema: (not (user$max-length2/fn--23140 "hello!"))
Thanks for the detailed question. Constrained takes a third argument with predicate name. Or you can just give the predicate function a name. Is that what you're looking for?
Best,
Jason
(s/constrained s/Int is-fib? is-square? is-prime? "complex constraint")
;;=> ExceptionInfo Value does not match schema: (not ("complex constraint" 76))