This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-27
Channels
- # announcements (2)
- # babashka (60)
- # beginners (73)
- # calva (23)
- # cider (2)
- # clj-kondo (19)
- # cljs-dev (31)
- # clojure (29)
- # clojure-berlin (1)
- # clojure-europe (6)
- # clojure-nl (17)
- # clojure-spec (21)
- # clojure-uk (15)
- # clojurescript (54)
- # core-async (48)
- # cursive (35)
- # datomic (12)
- # emacs (12)
- # fulcro (66)
- # graalvm (3)
- # graphql (16)
- # jackdaw (1)
- # malli (1)
- # off-topic (11)
- # pedestal (4)
- # re-frame (10)
- # reitit (1)
- # rewrite-clj (8)
- # ring-swagger (8)
- # shadow-cljs (14)
- # spacemacs (2)
- # vim (5)
what's the best way to spec a nested map? Say, I have a customer
map that looks something like this:
{:email ""
:password "horsecabbagetruck"
:first-name "John"
:last-name "Doe"
:organization
{:organization/settings
{:organization.setting/send-requests? true
:organization.setting/receive-requests? true}
:organization/name "Acme"}}
how would you go about validating these nested fields? Simply write a couple of spec registries and then collect them in an entity map? So you'd do:
(s/def ::customer (s/keys :req-un [::email ::password ::first-name ::last-name ::organization]))
and ::organization
would be specced to have the namespaced nested data? I'm a bit unsure on how to proceed since the official guide doesn't really have explicit examples of nested data as far as I can seeI'd say you're going in the right direction try the pattern you have posted, and verify if you are getting the desired validations. Else post the exact failed attempt here
cool, thanks for the help, guys
mini-survey: are folks using https://github.com/danielcompton/defn-spec or something similar? how do you like/dislike it?
I authored https://github.com/nedap/speced.def and we're happy with it at work. Since it compiles to a clojure/script defn
it has zero limitations or new syntax, guaranteed.
it doesn't preclude creating generic/reusable specs: you can author those and still use them here.
It has no :fn
equivalent (only :`args` :ret
ones), but honestly I have yet to see how that is not equivalently achieved with the occasional :pre
condition.
I haven't campaigned much about it so far, but I plan to post something to #news-and-articles later this week :)
@bbloom I don't use it -- I often put fdef
s in a separate namespace in libraries so they are optional and the code can then run on older Clojure versions.
(and I don't like that syntax so I wouldn't want to use it even when I would put fdef
s above the function for which they exist)
Seems like a lot of limitations as well https://github.com/danielcompton/defn-spec#limitations
thanks for the thoughts - i’m not using anything like it yet b/c i like to kinda use the primitives until i grok them fully and then and only then abstract more
Those limitations alone would make it non-viable for most of my fdef
use cases I think.
https://corfield.org/blog/2019/09/13/using-spec/ is about how we use it at World Singles Networks
i’ve been doing a lot of TypeScript for work lately, and all the inline annotations are simultaneously: laborious, helpful, and hurtful
thanks @seancorfield, that all makes sense to me - to some extent i’m trying to decide how far to do w/ development time checking
my current thinking is basically just-in-time specing, where i spec stuff as part of my debugging process and leave the specs around for future use
I've got a library like that in the works, probably 80% done at this point. Don't know if or when I'll finish it. But my focus is on fn specs, since those are the painful ones to write in my opinion. As well as multi-arity, var-args, et all. Those are the hard ones to write, so my DSL intends to make these way quicker to spec, as to encourage more spec writing. Right now the machinery attaches itself as metadata on defns, so it also is compatible with older Clojure versions.