Skip to content

Instantly share code, notes, and snippets.

@atroche
Last active June 13, 2016 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atroche/731f80376985773c60d5e943b38d8052 to your computer and use it in GitHub Desktop.
Save atroche/731f80376985773c60d5e943b38d8052 to your computer and use it in GitHub Desktop.
(s/def ::fn-takes-two-args
(s/fspec :args (s/cat :arg1 long?
:arg2 long?)
:ret long?
:gen (fn [] (fn [a b] (* a b)))))
=> :user/fn-takes-two-args
(defn fn-that-takes-fn-with-two-args [f]
(f 1 2))
=> #'user/fn-that-takes-fn-with-two-args
(s/fdef fn-that-takes-fn-with-two-args
:args (s/cat :function ::fn-takes-two-args))
=> user/fn-that-takes-fn-with-two-args
(s/valid? ::fn-takes-two-args
(fn [a b] (+ a b)))
=> true
(s/explain ::fn-takes-two-args
(fn bad-fn [a b c] (+ a b c)))
val: (0 0) fails spec: :user/fn-takes-two-args predicate: (apply fn), Wrong number of args (2) passed to: user/eval47132/bad-fn--47133
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment