This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-17
Channels
- # announcements (6)
- # babashka-sci-dev (6)
- # beginners (30)
- # cider (2)
- # clerk (34)
- # clj-kondo (2)
- # clojure (40)
- # clojure-europe (50)
- # clojure-germany (2)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-uk (2)
- # clojurescript (7)
- # conjure (2)
- # cursive (7)
- # events (3)
- # guix (1)
- # hyperfiddle (22)
- # lsp (2)
- # malli (3)
- # music (1)
- # off-topic (9)
- # re-frame (5)
- # reitit (3)
- # sql (1)
- # vim (3)
- # xtdb (5)
#malli
<
2023-03-17Add support for default/fallback branch for :map
(https://github.com/metosin/malli/pull/871) merged in master. Test/user reports welcome!
this is a nice bonus:
(m/decode
[:map-of :int :int]
{1 1, 2 "2", "3" 3, "4" "4"}
(mt/strip-extra-keys-transformer))
; => {1 1}
my colleague showed me some interesting behavior with decode. It has to do with what happens when a transformer throws. minimal example:
(mc/decode :sequential "32" (mtx/string-transformer))
It cropped up during a usage with an :or
like this:
(mc/decode [:or :sequential :int] "32" (mtx/string-transformer))
Which you’d expect would return 32
, but no. it throws:
clojure.lang.ExceptionInfo: :malli.core/child-error
{:type :malli.core/child-error, :message :malli.core/child-error, :data {:type :sequential, :properties nil, :children nil, :min 1, :max 1}}
at malli.core$_exception.invokeStatic (core.cljc:138)
malli.core$_exception.invoke (core.cljc:136)
:sequential
schema. the exception is getting thrown on schema creation.I believe it's the schema creation: try (m/schema :sequential)
, it requires 1 child, e.g
(m/schema [:sequential :any])
. m/decode
coerces the data syntax into schema.
heya, I’m trying to build a custom simple-schema using the example in the docs.
(def Between
(malli/-simple-schema
{:type `Between
:compile (fn [_properties [min max] _options]
(when-not (and (int? min) (int? max))
(malli/-fail! ::invalid-children {:min min, :max max}))
{:pred #(and (int? %) (>= min % max))
:min 2 ;; at least 1 child
:max 2 ;; at most 1 child
:type-properties {:error/fn (fn [error _] (str "should be betweeb " min " and " max ", was " (:value error)))}})}))
However I get a “child error”, when I try to use it
(malli/form [Between 10 20])
:malli.core/child-error
{:type :malli.core/child-error, :message :malli.core/child-error, :data {:type sqa.api-reitit.filter/Between, :properties nil, :children [10 20], :min 0, :max 0}}
It looks like malli.core/-simple-schema
is not getting the correct min and max values - it expects :max and :min at the top level of the map passed to it - but I changed that and got some other errors using the schema so there may be some other things I’m missing✅ 1