This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-09
Channels
- # announcements (3)
- # babashka (17)
- # beginners (75)
- # calva (43)
- # cider (1)
- # clj-kondo (54)
- # cljdoc (8)
- # cljs-dev (70)
- # clojure (83)
- # clojure-europe (27)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (8)
- # clojure-uk (13)
- # clojured (2)
- # clojurescript (47)
- # community-development (4)
- # conjure (2)
- # cursive (3)
- # datomic (5)
- # emacs (5)
- # events (3)
- # fulcro (13)
- # graalvm-mobile (19)
- # helix (2)
- # introduce-yourself (1)
- # jobs (2)
- # jobs-discuss (28)
- # kaocha (9)
- # livestream (11)
- # malli (15)
- # meander (24)
- # nextjournal (8)
- # off-topic (26)
- # pathom (1)
- # pedestal (8)
- # polylith (2)
- # portal (31)
- # re-frame (4)
- # reagent (10)
- # reitit (8)
- # remote-jobs (3)
- # sci (1)
- # shadow-cljs (66)
- # spacemacs (20)
- # testing (6)
- # vim (15)
- # xtdb (7)
Hello. I’m wondering how I can update a schema to dissoc a prop if the schema uses :and at the top-level. For example, if I have the following:
(def my-schema
[:and
[:map
[:id uuid?]
[:some-prop int?]
[:some-prop-2 int?]]
[:fn {:error/message "Some prop must be less than some prop 2"}
(fn [{:keys [some-prop some-prop-2]}]
(< some-prop some-prop-2))]])
and I want to dissoc :id
from the map, but keep everything else in the schema the same, how can I do that? I see the malli.util dissoc
function and others, but I’m not sure how to use them when :and is involved.Ah, it seems that (mu/update my-schema 0 mu/dissoc :id)
works, but maybe there is a better way?
There's a function for manipulating properties that might be worth looking at in case it makes intent clearer: (mu/update-properties)
.
for mu/merge
there is a kind of special case:
> * for :and schemas, the first child is used in merge, rest kept as-is
I wonder if that could (and should) be generalized to other malli.util operations
@U066SF64X I’m not sure if update-properties
can be used directly in this case, given the :and
, but maybe there’s a good way to use it in combination with another operation to make intent clearer.
@U05476190 Yeah :thinking_face:.
HI, I have this spec which is being used by a reitit route, I am having issues where it fails because the value is a string instead of a keyword, I have been trying to use the json transformer but I think it fails because its not specifically a keyword test, any suggestion on how I could solve this ?
[:or
[:map {:closed true}]
[:map {:closed true}
[:start [:enum :january :feburary :march :april :may :june :july :august :september :october :november :december]]
[:end [:enum :january :feburary :march :april :may :june :july :august :september :october :november :december]]]]
So i am running the spec through the json-transformer decoder but I dont think it handles this case because its of enum type not keyword
I am currently looking at -json-decoders trying to see if I can add to that some how
[:category/type {:optional true} keyword?]
currently the above is working as intended, feels like i need to extend some where I tried adding [:and keyword? [:enum :one :two]] but that does not trigger the conversionIs there a :seqable
schema that would allow you to specify the children’s type? I’m running into an issue where I’d like to have a function accept a vector, list or set of a particular entity, but haven’t been able to figure out how to build the correct collection schema for it. I’m assuming I should be using malli.core/-collection-schema
to add a custom schema to the registry
You can also just define the Schema as Var as use it without registering, like Reagent compoents:
(def Seqable (m/-collection-schema {:type 'Seqable, :pred seqable?}))
(m/validate [Seqable :int] '(1 2 3)) ; => true