This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-23
Channels
- # announcements (3)
- # asami (5)
- # babashka (1)
- # beginners (38)
- # biff (4)
- # calva (12)
- # cider (2)
- # clj-commons (6)
- # clj-kondo (46)
- # clj-on-windows (1)
- # clojure (50)
- # clojure-europe (41)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-uk (16)
- # clojured (3)
- # clojurescript (49)
- # conjure (1)
- # cursive (29)
- # datahike (6)
- # datascript (4)
- # emacs (70)
- # funcool (1)
- # google-cloud (12)
- # graalvm (10)
- # graalvm-mobile (7)
- # gratitude (4)
- # hyperfiddle (1)
- # joyride (26)
- # lsp (16)
- # malli (23)
- # nbb (5)
- # off-topic (23)
- # polylith (32)
- # re-frame (23)
- # releases (3)
- # remote-jobs (1)
- # reveal (3)
- # tools-build (16)
- # xtdb (50)
Hello, I've a question about the behaviour of :and.
Here is a schema with a valid input:
(m/explain [:and
[:sequential any?]
[:multi {:dispatch 'first}
[:a [:sequential keyword?]]
[::m/default any?]]]
[:a :b])
=> nil
but with invalid input
(m/explain [:and
[:sequential any?]
[:multi {:dispatch 'first}
[:a [:sequential keyword?]]
[::m/default any?]]]
1)
Execution error (IllegalArgumentException) at malli.core/-multi-schema$reify$reify$fn (core.cljc:1497).
Don't know how to create ISeq from: java.lang.Long
I was expecting that the branch that checks that the input is sequential would prevent execution of the second oneThe solution I found to avoid an exception to be raised is to have smarter dispatch function
(m/explain [:multi {:dispatch (fn [x] (if (seq? x) (first x) ::error))}
[:a [:sequential keyword?]]
[::error [:sequential any?]]
[::m/default any?]]
1)
=>
{:schema ...,
:value 1,
:errors ({:path [:muguet.meta-schemas/error],
:in [],
:schema [:sequential any?],
:value 1,
:type :malli.core/invalid-type})}
Why checking branches in an :and is not lazy (could stop after one of the branch is invalid) ?
Hi. I'm very not expert in malli, but maybe it's the use of explain
: explain try to give all the reasons why it's not valid. Let's say you have a password that must have a specific length, some special characters, etc. You may want to display all the reasons at once instead of a "one by one" strategy. But a lazy version would be useful I think. (I didn't check but validators
should already be lazy)
Is it possible to remove a key-value-pair from a map during decode if the value is a specific thing? I've got a select with an entry that reads "all" which is functionally the same as not giving any value at all and I want to handle that case in the reitit/malli request param coercion stage.
I think I've found a relevant example:
(m/decode
[string? {:decode/string {:enter 'str/upper-case}}]
"kerran" mt/string-transformer)
Though that won't remove the key:
(malli.core/decode [:map [:a [:string {:decode/string #(if (= "all" %) nil %)}]]]
{:a "all"}
malli.transform/string-transformer)
;; => {:a nil}
Para on IRC gave me a solution:
(defn- remove-alla-odlingsplatser
"Takes a query-params map and removes the key :odlingsplatser if its value is 'alla odlingsplatser'."
[m]
(if (= "alla odlingsplatser" (:odlingsplats m))
(dissoc m :odlingsplats)
m))
I want to use malli/decode
on a map that has to contain at least one of :foo/id URI
or :bar/id UUID
. No matter how I twist and turn the schema, the only thing I can get working is the following:
(malli/decode [:or
[:map
[:foo/id uri?]
other-child
other-other-child]]
[:map
[:bar/id uuid?]
other-child
other-other-child]]]
{:bar/id #uuid "15a0bc27-5725-41d9-89c9-6f8d3966447a"
:other-key :other-value}
(mt/transformer mt/strip-extra-keys-transformer mt/string-transformer))
Is there a good way to handle this without having to duplicate the schema?Thanks for the suggestion! Unfortunately they are different keys, one of which always corresponds to a URI and the other to a UUID.
[:map
[:or [:foo/id uri?]]
[:bar/id uuid?]]
[:attr1 :int]
[:attr2 :int]]
Something like the above is what I would like to achieve.[:union
[:or
[:map [:foo/id uri?]]
[:map [:bar/id uuid?]]]
[:map
[:attr1 :int]
[:attr2 :int]]]