This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-29
Channels
- # adventofcode (11)
- # aws (2)
- # bangalore-clj (8)
- # beginners (92)
- # boot (2)
- # calva (26)
- # cider (1)
- # clj-kondo (4)
- # cljs-dev (4)
- # clojure (54)
- # clojure-berlin (5)
- # clojure-houston (6)
- # clojure-italy (12)
- # clojure-nl (7)
- # clojure-uk (39)
- # clojurescript (12)
- # clojutre (6)
- # cryogen (1)
- # cursive (15)
- # datomic (11)
- # duct (1)
- # events (5)
- # fulcro (14)
- # jackdaw (1)
- # joker (2)
- # malli (15)
- # mental-health (1)
- # off-topic (35)
- # reagent (2)
- # reitit (24)
- # rewrite-clj (3)
- # shadow-cljs (19)
- # vim (11)
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.
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?
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
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
(m/decode
[:and [int? {:decode/string '(constantly {:enter (partial + 2), :leave (partial * 3)})}]]
"1"
mt/string-transformer)
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.
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)
You can rip it out of Clojure quite easily (https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L283)
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.
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…