Advertisement
Guest User

Untitled

a guest
May 29th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. (require '[clojure.spec :as s])
  2.  
  3. (s/fdef clojure.core/subs
  4. ;; the args are a string, integer and optionally another integer
  5. :args (s/cat :s string? :start integer? :end (s/? integer?))
  6. ;; the return value should be a string
  7. :ret string?
  8. ;; the input string should include the returned string
  9. :fn #(clojure.string/includes? (-> % :args :s) (:ret %)))
  10.  
  11. (s/instrument #'clojure.core/subs)
  12.  
  13. (subs 1 2 3) ;; =>
  14.  
  15. ;; ExceptionInfo Call to #'clojure.core/subs did not conform to spec:
  16. ;; In: [0] val: 1 fails at: [:args :s] predicate: string?
  17. ;; :clojure.spec/args (1 2 3)
  18. ;; clojure.core/ex-info (core.clj:4617)
  19.  
  20. (subs "foo" 1 2) ;; => "o", satisfies :ret and :fn obviously
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement