(f 1 {:a 2 :B 3})(require '[clojure.spec :as s])
(require '[clojure.spec.test :as stest])
(s/def ::x (fn [x] true)) ;for lack of any?
;; Will not catch invalid keywords
(s/fdef f
:args (s/cat :x ::x
:options (s/keys :opt-un [::a ::b]))
:ret nil?)
;; Will catch invalid keywords, but is there an easier way?
(s/fdef f
:args (s/cat :x ::x
:options (s/and (s/keys :opt-un [::a ::b])
#(every? #{:a :b} (keys %))))
:ret nil?)
(defn f [x {:keys [a b]}])
(stest/instrument `f)
We don't encourage you to do this, but I don't have an easier solution than this.
Hello Alex,
The idea is (as I understand it) that every function should accept any
map and pick keys which it understands. If some keys are critical, then
they should be marked as such in the spec.
Function might iterate over keys and raise an error if there are keys
which belong to the namespace function cares about, but the names are
not known, but it is outside of spec's functionality and ought to be
done manually.
Best regards,
Mikhail.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ugh, don't do that. Introducing layers that add no value is a bad idea. Just use the keyword directly.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
A good editor should auto-complete your keywords for you. Since using this feature in Cursive (same sort of thing is available in other editors) the cases where I've mis-spelled a keyword have dropped dramatically. It's a lot harder to mis-spell a keyword when you can just do: :egg/th<enter> and the rest is auto-filled.
On Thu, Feb 2, 2017 at 5:37 PM, Alex Miller <al...@puredanger.com> wrote:
Ugh, don't do that. Introducing layers that add no value is a bad idea. Just use the keyword directly.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.