This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-19
Channels
- # adventofcode (82)
- # beginners (70)
- # boot (34)
- # boot-dev (13)
- # cider (45)
- # clara (4)
- # cljs-dev (3)
- # cljsrn (2)
- # clojure (91)
- # clojure-art (8)
- # clojure-czech (1)
- # clojure-dusseldorf (3)
- # clojure-france (11)
- # clojure-germany (1)
- # clojure-greece (39)
- # clojure-hamburg (1)
- # clojure-italy (24)
- # clojure-norway (2)
- # clojure-spec (7)
- # clojure-uk (31)
- # clojurescript (56)
- # core-async (7)
- # cursive (8)
- # data-science (10)
- # datomic (41)
- # duct (7)
- # emacs (1)
- # events (1)
- # fulcro (83)
- # graphql (6)
- # klipse (1)
- # leiningen (28)
- # lumo (67)
- # off-topic (14)
- # om (9)
- # onyx (3)
- # perun (4)
- # re-frame (22)
- # reagent (11)
- # ring-swagger (2)
- # rum (1)
- # specter (46)
- # sql (13)
- # uncomplicate (17)
- # unrepl (114)
I am trying to write specs for a function whose argument can be nil or a collection. However, I am unable to combine those two using s/or
. This is what I tried -
(s/fdef my-func
:args (s/cat :arg1 (s/or :nil nil? :collection list?)))
This definitely won't work but it'd be great to have the option -
..... (s/or nil? list?)
can’t you do
(s/def ::arg1 (s/nilable list?))
then just use that with s/cat :arg1 ::arg1 ?
Ah! I wasn't aware of s/nilable
. Thanks!
However, I am not sure why but (s/nilable coll?)
works and s/nilable list?
doesn't when the data structure is actually a list of maps (or nil).
@fravani because list?
is only true for things that implement IPersistentList
-- which a lazy sequence does not.
But coll?
is true for IPersistentCollection
and LazySeq
does implement that.