How can I get Clojure :pre & :post to report their failing value?

后端 未结 4 1554
粉色の甜心
粉色の甜心 2020-12-05 06:42
(defn string-to-string [s1] 
  {:pre  [(string? s1)]
   :post [(string? %)]}
  s1)

I like :pre and :post conditions, they allow me to figure out wh

4条回答
  •  不思量自难忘°
    2020-12-05 07:36

    Something like below where clojure spec is explaining the problem? This will throw an assertion error which you can catch.

     (defn string-to-string [s1] 
      {:pre [ (or (s/valid?  ::ur-spec-or-predicate s1) 
                  (s/explain ::ur-spec-or-predicate s1)]}
      s1)
    

提交回复
热议问题