This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-30
Channels
- # babashka (44)
- # beginners (29)
- # calva (80)
- # cider (11)
- # clara (1)
- # clj-kondo (9)
- # clojure (80)
- # clojure-europe (21)
- # clojure-france (13)
- # clojure-nl (4)
- # clojure-spec (3)
- # clojure-uk (6)
- # clojurescript (72)
- # code-reviews (43)
- # cursive (11)
- # datomic (27)
- # events (13)
- # figwheel-main (12)
- # fulcro (27)
- # graalvm (1)
- # jackdaw (2)
- # kaocha (1)
- # malli (4)
- # meander (13)
- # nrepl (2)
- # pathom (8)
- # re-frame (4)
- # reagent (7)
- # reitit (9)
- # remote-jobs (1)
- # reveal (56)
- # ring-swagger (2)
- # sci (5)
- # shadow-cljs (20)
- # slack-help (2)
- # tools-deps (96)
- # vim (7)
- # xtdb (32)
as one string? Maybe something like:
(m/decode
[:vector {:decode/string (partial str/split ",")} int?]
"1,2,4,8,10"
mt/string-transformer)
not near a computer, so not 100% sure it worksThanks, I'll give that a try. I came up with this but your solution seems simpler:
(defn ids?
"Takes in a string and returns true if that string is of the form
1,4,7,9 or a sequence (in the math sense) of positive integers."
[data]
(let [ids (-> data
(clojure.string/split #",")
(as-> ids (mapv #(Integer/parseInt %) ids)))]
(every? pos? ids)))
(def GetClassesQueryOptions
[:map
[:approved {:optional true} boolean?]
[:instructors {:optional true} [:fn (fn [ids] (ids? ids))]]
[:machine {:optional true} [:fn (fn [ids] (ids? ids))]]
[:music {:optional true} [:fn (fn [ids] (ids? ids))]]
[:bookmarked {:optional true} boolean?]
[:minlength {:optional true} int?]
[:maxlength {:optional true} pos?]])
It's good to keep decoding and validation in separate steps. @alexmiller has many times called the spec conform "a meat grinder", as it bundles the two and runs the transformations every time.
6