Fork me on GitHub
#malli
<
2020-08-12
>
ikitommi07:08:13

the transformation terms: • transformation function, a function of A->B, e.g. converts strings to dates • decoding, a process of transforming (invalid) values into potentially valid ones (IN*), m/decoder& m/decode* • encoding, a process of transforming (valid) values into something else (OUT), m/encoder & m/encodetransformer, a top-level component that maps Schemas with transformation functions (“json-transformer transforms strings to dates, but not strings to numbers”). Needed in encoding and decoding, mt/transformernamed transformer, If a transformer has :name defined, Schemas can define their transformation functions (for both encoding & decoding) using Schema properties • interceptor, a component that bundles transforming functions into transforming phases • transforming phase, either :enter or :leave, timing when a transformation function is applied in the chain (before the fact or after the fact) • interceptor chain, a sequence of interceptors that is used to run the (optimized chain of) transformation functions from interceptors in correct order • transformation chain , transformers compose too: (mt/transformer {:name :before} mt/json-transfomer {:name :after})

ikitommi07:08:13

the transformation terms: • transformation function, a function of A->B, e.g. converts strings to dates • decoding, a process of transforming (invalid) values into potentially valid ones (IN*), m/decoder& m/decode* • encoding, a process of transforming (valid) values into something else (OUT), m/encoder & m/encodetransformer, a top-level component that maps Schemas with transformation functions (“json-transformer transforms strings to dates, but not strings to numbers”). Needed in encoding and decoding, mt/transformernamed transformer, If a transformer has :name defined, Schemas can define their transformation functions (for both encoding & decoding) using Schema properties • interceptor, a component that bundles transforming functions into transforming phases • transforming phase, either :enter or :leave, timing when a transformation function is applied in the chain (before the fact or after the fact) • interceptor chain, a sequence of interceptors that is used to run the (optimized chain of) transformation functions from interceptors in correct order • transformation chain , transformers compose too: (mt/transformer {:name :before} mt/json-transfomer {:name :after})

suomi.esko10:08:42

Could be valuable to add these as glossary doc to the repository (`docs/glossary.md`) to document them :+1:

ikitommi07:08:49

lot of things inside to make things composable and fast, the basic user doesn’t have to know much of the details.

ikitommi07:08:01

(m/decode
  [:map
   [:x {:default 42} int?]
   [:y [:vector {:decode/before #(str/split % #",")
                 :decode/after {:leave #(mapv inc %)}} int?]]]
  {:y "1,2,3"}
  (mt/transformer
    {:name :before}
    (mt/default-value-transformer)
    (mt/string-transformer)
    {:name :after}))
;{:y [2 3 4]
; :x 42}

ikitommi07:08:58

(m/decode
  [:map
   [:x {:default 42} int?]
   [:y [:vector {:decode/before #(str/split % #",")
                 :decode/after {:leave #(mapv inc %)}} int?]]]
  {:y "1,2,3"}
  (mt/transformer
    {:name :before}
    (mt/default-value-transformer)
    (mt/string-transformer)
    {:decoders {'int? #(* % 2)}}
    {:name :after}))
;{:y [3 5 7]
; :x 84}