This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-04
Channels
- # architecture (9)
- # babashka (33)
- # beginners (53)
- # biff (3)
- # cljdoc (11)
- # clojure (8)
- # clojure-austria (2)
- # clojure-dev (9)
- # clojure-europe (64)
- # clojure-nl (2)
- # clojure-norway (49)
- # clojure-sweden (4)
- # clojure-uk (4)
- # clojurescript (16)
- # cursive (14)
- # datahike (31)
- # datalevin (6)
- # datascript (9)
- # events (1)
- # fulcro (4)
- # honeysql (8)
- # hyperfiddle (116)
- # introduce-yourself (1)
- # kaocha (2)
- # malli (13)
- # nyc (2)
- # off-topic (4)
- # polylith (5)
- # portal (1)
- # reagent (1)
- # reitit (18)
- # releases (1)
- # spacemacs (6)
Is spec the right tool for the following case: Check if the input of a function is a member of a vector, e.g. (func "A")
where the arg
has to be either A
, B
or C
.
I'm trying to learn spec from the spec guide but the only mention of something similar is using s/coll-of
.
Yes, but I've failed to incorporate this into spec and a function with s/fdef
(defn func [arg] arg)
(s/fdef func
:arg (s/cat :arg #{:club :diamond :heart :spade}))
(func :foo) ; => :foo
I think you just want :args
rather than :arg
in the fdef:
(defn frob [x] x)
(spec/fdef frob :args (spec/cat :thing #{"a" "b" "c"}))
(st/instrument `frob)
(frob "b")
;; => "b"
(frob "d")
;; Execution error - invalid arguments...
Correct, in addition to the typo my CIDER repl was broken for some reason (e.g. no error with your example), restarting made it work.