This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-07
Channels
- # adventofcode (62)
- # babashka (88)
- # beginners (52)
- # boot (2)
- # bristol-clojurians (1)
- # calva (7)
- # cider (15)
- # circleci (4)
- # clj-kondo (12)
- # cljdoc (5)
- # cljsrn (4)
- # clojure (53)
- # clojure-dev (1)
- # clojure-spec (7)
- # clojure-uk (7)
- # clojurescript (25)
- # core-async (14)
- # duct (1)
- # emacs (10)
- # figwheel-main (3)
- # fulcro (11)
- # garden (14)
- # jobs (1)
- # klipse (2)
- # luminus (1)
- # malli (9)
- # re-frame (6)
- # reagent (13)
- # remote-jobs (1)
- # shadow-cljs (124)
- # sql (1)
- # testing (15)
- # tools-deps (13)
- # uncomplicate (1)
- # vim (1)
hm ok… but should the`-transformer` function return a function that returns transform function? Because so far it just seems that it brings a lot of constantly
use
I see so much constantly
use that I wonder what is the other case (i.e. non-constantly)
-transformer
already sees the schema, so it can return directly an .... interceptor? The later comment shows how we can get rid of vobstantly
in the schema properties too: https://github.com/metosin/malli/issues/136#issuecomment-562731476
the current internal vocabulary is quite messy, would these be good names for the future:
* method
:decode :encode
* stage
:enter :leave
* context
:json :string :before :after ...
:enter/:leave and chain of contexts enable same kind of things. Wondering do we need them both…
(def transformer (mt/transformer {:name :before} mt/string-transformer {:name :after}))
(m/decode
[:and
{:decode/after 'inc}
int?]
"1"
transformer)
; => 2
; :enter
; :before
; :strip-keys
; :string => ->int "1" => 1
; :after => inc 1 => 2
; :leave
; :after
; :string
; :strip-keys
; :before
(m/decode
[:and
{:decode/before {:leave 'inc}}
int?]
"1"
transformer)
; => 2
; :enter
; :before
; :strip-keys
; :string => ->int "1" => 1
; :after
; :leave
; :after
; :string
; :strip-keys
; :before => inc 1 => 2
Did a small spike, seems to work, so PR out. Simplifies the Transformer
Protocol and enables chaining of tranformers (instead of overriding schema-based encoder & decoders like before). Also, better naming of things https://github.com/metosin/malli/pull/137
(m/decode
[int? {:decode/before '(constantly {:leave inc})
:decode/after '(constantly (partial * 2))}]
"10"
(mt/transformer
{:name :before}
mt/string-transformer
{:decoders {'int? (constantly inc)}} ;; anonymous
{:name :after}))
; => 23
;; :enter
;; :string "10" => 10
;; anonymous 10 => 11
;; :after 11 => 22
;; :leave
;; :before 22 => 23