This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-28
Channels
- # asami (5)
- # babashka (44)
- # beginners (22)
- # biff (7)
- # clerk (86)
- # clj-kondo (5)
- # clojure (33)
- # clojure-europe (8)
- # clr (6)
- # community-development (2)
- # fulcro (20)
- # graalvm (5)
- # graphql (1)
- # hugsql (3)
- # integrant (5)
- # java (11)
- # joyride (2)
- # leiningen (4)
- # malli (12)
- # nbb (15)
- # off-topic (28)
- # pathom (23)
- # reitit (8)
- # releases (1)
- # sci (6)
- # shadow-cljs (39)
- # tools-deps (15)
- # tree-sitter (1)
Can I define a generator for [:map [:a :string] [:b string]]
such that I can :gen/fmap
the :b
based on the generated value of :a
?
eg. if using faker I can generate:
{:company-name "Acme Inc"}
but I'd like to slugify the name via some function:
{:company-name "Acme Inc.", :slug "acme"}
hey y’all, is there a way to create a map spec where all the keys are optional, but values must have one of the keys to be valid?
eg given [:map [:a {:optional true}] [:b {:optional true}]]
, then {:a :foo}
would be valid but {:c :foo}
would not
i can think of [:or [:map [:a]] [:map [:b]]]
but that seems clunky?
well, it sounds like you don’t want optional but you’re actually modeling a union type - I’d go with :multi
or :or
- but if that feels clunky you probably need an :and
where you first spec the map and then check with custom fn that at least one of the expected keys exists.
(You’ve still got things like :merge
to help you pull out the repetitive parts of the individual unions)
thank you!