Fork me on GitHub
#malli
<
2019-11-29
>
ikitommi05:11:22

hmm… I think the :dispatch doesn’t need a separate leave?

ikitommi05:11:29

as the dispatch is used to select the schema when going in, when returning, we don’t need the selection, we just go back the same route.

ikitommi06:11:15

Hmm,.. after mt/transformer chains the interceptors for the same schema key (instead of overriding), what if the names are also chained so that one could define multiple schema-based decode/encode via schema properties?

ikitommi06:11:10

e.g. (mt/transformer {:name :enter} mt/string-transformer {:name :leave}) would make a name chain of [:enter :string :leave] which would allow fine grained control of overriding things in the schemas:

(m/decode
  [:and {:decode/enter (constantly inc), 
         :decode/string (constantly (partial * 2))
         :decode/leave (constantly (partial + 10))} int?]
  1
  (mt/transformer {:name :enter} mt/string-transformer {:name :leave}))
; => 30

ikitommi06:11:05

more common case would be to “after normal decoding, do this too”:

(m/decode
  [:and {:decode/leave (constantly (partial + 10))} int?]
  "1"
  (mt/transformer {:name :enter} mt/string-transformer {:name :leave}))
; => 11

ikitommi06:11:46

getting complex, not sure if this is a good idea.

eskos06:11:47

Not going to lie, I had to read that about 5 times to grok it…

ikitommi06:11:19

(m/decode
  [:and [int? {:decode/string '(constantly {:enter (partial + 2), :leave (partial * 3)})}]]
  "1"
  mt/string-transformer)

ikitommi06:11:26

currently, that doesn’t work, as there is no way to compose the normal transformation and a custom one. if you define anything at schema-level, it overrides the default. might be ok and just needs to be documented.

ikitommi06:11:09

btw, do you @borkdude have a defn-parser in some of your utility libs? would be great not need to reinvent the wheel with the schema defn -syntax, expecially if malli already depends on that functionality (sci or edamame)

eskos06:11:21

And if that feels dangerous, I’ve made one incomplete implementation of defn parser with clojure.tools.reader a while back because I needed to analyze defn s (don’t ask) and ended up with this sort of bleh thing which eats defn s and produces data maps.

eskos06:11:52

I’m sharing that just for the idea, it’s obviously not complete 😛 In fact I should continue this project, I’ve been sitting on it for far too long…

borkdude07:11:24

@ikitommi there is a defn parser in sci of course but I haven’t thought about sharing it so it might be a little specific for sci

borkdude07:11:12

In edamame there is a fn literal -> fn parser feature