malli

https://github.com/metosin/malli :malli:
ikitommi 2020-08-12T07:08:13.386Z

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})

ikitommi 2020-08-12T07:08:49.386700Z

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

ikitommi 2020-08-12T07:23:01.387300Z

(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}

ikitommi 2020-08-12T07:24:58.387600Z

(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}

eskos 2020-08-12T10:33:42.387800Z

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

👍 2