Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require '[clojure.spec :as s])
- (s/fdef clojure.core/subs
- ;; the args are a string, integer and optionally another integer
- :args (s/cat :s string? :start integer? :end (s/? integer?))
- ;; the return value should be a string
- :ret string?
- ;; the input string should include the returned string
- :fn #(clojure.string/includes? (-> % :args :s) (:ret %)))
- (s/instrument #'clojure.core/subs)
- (subs 1 2 3) ;; =>
- ;; ExceptionInfo Call to #'clojure.core/subs did not conform to spec:
- ;; In: [0] val: 1 fails at: [:args :s] predicate: string?
- ;; :clojure.spec/args (1 2 3)
- ;; clojure.core/ex-info (core.clj:4617)
- (subs "foo" 1 2) ;; => "o", satisfies :ret and :fn obviously
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement