This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-07
Channels
- # announcements (1)
- # babashka (77)
- # beginners (219)
- # chlorine-clover (6)
- # cider (52)
- # clj-kondo (14)
- # cljdoc (5)
- # clojure (173)
- # clojure-europe (49)
- # clojure-finland (1)
- # clojure-germany (2)
- # clojure-italy (1)
- # clojure-nl (39)
- # clojure-sweden (4)
- # clojure-uk (51)
- # clojurescript (25)
- # code-reviews (9)
- # conjure (25)
- # data-science (2)
- # figwheel-main (6)
- # fulcro (74)
- # graalvm (1)
- # graphql (11)
- # jobs-discuss (17)
- # keechma (4)
- # lein-figwheel (4)
- # leiningen (1)
- # luminus (10)
- # malli (14)
- # mid-cities-meetup (2)
- # off-topic (28)
- # re-frame (5)
- # reagent (76)
- # reitit (30)
- # ring (7)
- # ring-swagger (1)
- # shadow-cljs (163)
- # spacemacs (11)
- # specter (2)
- # sql (43)
- # tools-deps (13)
- # vim (6)
- # yada (1)
I can’t get Union
working on my schemas
This is the gist with the schemas in it.
@grounded_sage it seems neither of those are valid schemas, I split the first one and reduced it into this which fails
user=> (m/validator [:map
#_=> [:Data
#_=> [:map
#_=> [:GroupMemberships [:vector [:or]]]]]])
Execution error (ExceptionInfo) at malli.core/fail! (core.cljc:73).
:malli.core/no-children
Yea I thought that was strange. Can malli generate invalid schemas?
Because this was after doing schema inference.
If that is a result of inferring then I guess the answer is yes 🙂 If you can figure out the minimal set of input data which produces invalid inferred schemas, I’m sure an issue is warmly welcomed.
Just posted an issue for it. https://github.com/metosin/malli/issues/196
Anyone now if this is possible? :spritesheet/frame
and :spritesheet/animation
are technically both optional. But the map MUST have one or the other. This code snippet is invalid, the :or
doesn't work (disclaimer, I'm working off of this PR https://github.com/metosin/malli/pull/194 which is why I can use this qualified-keyword syntax)
The way I've done such xor
-like unions in regular spec is to move the or
up one level:
[:or
[:map
:spritesheet/name
:spritesheet/frame]
[:map
:spritesheet/name
:spritesheet/animation]]
Let's say I have a value that is an enum:
(def Weighting
[:enum :dB-A :dB-C :dB-Z])
I can specify that as a value in another schema:
(def MyMap
(m/schema
[:map
[:weighting Weighting]]))
Is there a way to turn the value schema into a "type" that malli understands?
Let's say I need to transform the numbers 0,1,2 into the enumerated values...
(defn weighting->kw
[n]
(if (int? n)
(case n
0 :dB-C
1 :dB-A
2 :dB-Z
n)
n))
I specify a value transformer as:
(mt/transformer
{:name :weighting
:decoders {:enum weighting->kw}})
But in writing this, I am reaching into Weighting to pull out the :enum
If I had two different enum values then dispatching via "value is an enum" doesn't seem like it will work, they will both resolve to enum.
How does one handle this?
Seems like I would want to specify the decoder as {:Weighting weighting->kw}