Fork me on GitHub
#malli
<
2020-04-07
>
grounded_sage02:04:56

I can’t get Union working on my schemas

grounded_sage02:04:19

This is the gist with the schemas in it.

eskos08:04:26

@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

eskos08:04:35

That :or seems lingering, typo?

grounded_sage08:04:09

Yea I thought that was strange. Can malli generate invalid schemas?

grounded_sage08:04:19

Because this was after doing schema inference.

eskos08:04:59

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.

ikitommi09:04:43

Sounds like a bug.

kwrooijen21:04:10

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)

aisamu13:04:37

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]]

dcj23:04:21

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}