Fork me on GitHub
#clojure-europe
<
2020-09-10
>
slipset05:09:23

God morgen!

6
synthomat05:09:16

goedemorgen!

plexus07:09:44

Guten Morgen!

otfrom12:09:09

having a lot of fun with x/by-key and x/reduce today

genRaiy14:09:14

since we're talking functions - enjoying the function, new since 1.10 read+string

synthomat20:09:58

clojure-spec is weird; why doesn’t it complain about specific missing keys in a map? 😞

synthomat20:09:16

am I holding it wrong?

dominicm20:09:12

@synthomat did you mark them as :req?

synthomat20:09:43

explain-data just says “something’s wrong” but doesn’t say “something’s wrong because username is missing”

synthomat20:09:42

(s/def ::username (s/and string? #(re-matches #"[a-z0-9_]{2,18}" %) ::not-reserved-name?))
(s/def ::form (s/keys :req-un [::username]))

synthomat20:09:01

input of {} just gives this:

#:clojure.spec.alpha{:problems ({:path [],
                                 :pred (clojure.core/fn [%] (clojure.core/contains? % :username)),
                                 :val {},
                                 :via [:linksourcer.web.accounts.validators/form],
                                 :in []}),
                     :spec :linksourcer.web.accounts.validators/form,
                     :value {}}

synthomat20:09:35

whereas {:username "a"} returns this:

#:clojure.spec.alpha{:problems ({:path [:username],
                                 :pred (clojure.core/fn [%] (clojure.core/re-matches #"[a-z0-9_]{2,18}" %)),
                                 :val "a",
                                 :via [:linksourcer.web.accounts.validators/form
                                       :linksourcer.web.accounts.validators/username],
                                 :in [:username]}),
                     :spec :linksourcer.web.accounts.validators/form,
                     :value {:username "a"}}

ordnungswidrig21:09:35

Hmm it says at that at path location [] (root) the key`:username` is missing

ordnungswidrig21:09:48

Which is different form at [:username] the value xyz is invalid

dominicm21:09:31

^. :req is a map property, rather than a property of a key.