This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-28
Channels
- # announcements (2)
- # babashka (36)
- # beginners (29)
- # bristol-clojurians (2)
- # calva (3)
- # cider (102)
- # circleci (7)
- # clj-kondo (5)
- # cljs-dev (7)
- # clojure (117)
- # clojure-europe (23)
- # clojure-korea (1)
- # clojure-nl (1)
- # clojure-spec (15)
- # clojure-uk (47)
- # clojurescript (43)
- # code-reviews (1)
- # community-development (1)
- # conjure (32)
- # cursive (1)
- # datalog (15)
- # datomic (14)
- # emacs (18)
- # fulcro (9)
- # helix (23)
- # jackdaw (1)
- # jobs-discuss (10)
- # meander (8)
- # membrane (57)
- # off-topic (4)
- # portal (2)
- # re-frame (22)
- # reagent (1)
- # reitit (9)
- # reveal (3)
- # rewrite-clj (14)
- # shadow-cljs (22)
- # spacemacs (27)
- # sql (34)
- # testing (6)
- # tools-deps (40)
- # vim (5)
- # vrac (15)
- # xtdb (2)
also is there a way to get the generators for different items in a nested map to be consistent? i.e. for instance if i had a map like:
(s/def ::begin-date inst?)
(s/def ::end-date inst?)
(s/def ::dates (s/keys :req-un [::begin-date ::end-date]))
how can i get begin-date to be less than end-date in the generated output? sorry if this is documented somewhere 🙂@lpanda2014 You can wrap the s/keys
part with s/and
and add a predicate to check that #(some-date-lib/after? (::begin-date %) (::end-date %))
thanks! for some reason that didn’t work though 😞 had to change it to ints since i dont have a datetime library in my repl but the below code gave me a null ptr when i went to generate. is my syntax off?
(s/def ::begin-date int?)
(s/def ::end-date int?)
(s/def ::dates (s/and
(s/keys :req-un [::begin-date ::end-date])
#(> (::end-date %) (::begin-date %))))
(gen/generate (s/gen ::dates)) ;; broken
https://github.com/stackoverflow/date-clj is a simple library for manipulating dates, that has before/after comparisons. We use that at work.
(most of the date utility libraries have a simple function to check if one date is after another -- don't know what or if you're using)
Needs a custom gen too. Something like (gen/fmap #(zipmap [:begin-date :end-date] (sort %)) (s/gen (s/tuple inst? inst?)))
thanks! this worked like a charm
(s/def ::dates (s/with-gen
(s/keys :req-un [::begin-date ::end-date])
#(gen/fmap (fn [d] (zipmap [:begin-date :end-date] (sort d))) (s/gen (s/tuple inst? inst?)))))
Ah, good point. I couldn't remember whether java.util.Date
had comparison built-in (and was too lazy to check the Java API docs 🙂 )