This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-07
Channels
- # announcements (38)
- # asami (14)
- # beginners (35)
- # biff (3)
- # calva (29)
- # cider (20)
- # clj-kondo (7)
- # cljdoc (38)
- # clojure (64)
- # clojure-art (2)
- # clojure-australia (1)
- # clojure-dev (6)
- # clojure-europe (30)
- # clojure-nl (4)
- # clojure-spec (4)
- # clojure-uk (9)
- # clojured (3)
- # clojurescript (87)
- # cursive (17)
- # datahike (2)
- # datomic (10)
- # defnpodcast (2)
- # emacs (2)
- # events (1)
- # fulcro (25)
- # gratitude (1)
- # introduce-yourself (1)
- # jobs-discuss (21)
- # lsp (103)
- # malli (41)
- # meander (8)
- # minecraft (3)
- # missionary (3)
- # nextjournal (20)
- # off-topic (10)
- # pedestal (1)
- # polylith (15)
- # portal (6)
- # releases (2)
- # ring (1)
- # ring-swagger (2)
- # sci (4)
- # shadow-cljs (5)
- # spacemacs (3)
- # sql (11)
- # xtdb (3)
Where does it make sense in your opinion to specify keywords renaming for a transformer? in a map schema's property or on its entry?
My intuition says it belongs to the map. But I guess, it depends. Being part of the entry-tuple, you could for example merge two maps with mapping to same domain and the mappings would be merged automatically
e.g.
[:merge
[:map [:a {:rename/SAP "SAP_A", :rename/SALESFORCE "sf_a"} int?]]
[:map [:b {:rename/SAP "SAP_B"} int?]]]
not actually sure if the entry properties get merged correctly here, just guessing 🙂
Followup harder question - if I rename in decode it reports error on the wrong key path!
The only way I see around it is attaching as metadata the rename mappings and encode the error report on response
(defn key-renamer
"Take a tuple of keys [`k1` `k2`] and return a function of a map `m`
which will replace `k1` with `k2` if it exists in `m`"
[[k1 k2]]
(fn -rename [m]
(if-let [[_ v] (find m k1)]
(dissoc (assoc m k2 v) k1)
m)))
(defn- -compile-rename-keys-transformer
"Takes a map of keys->keys and returns a function which will rename the
keys in LHS to RHS if they exist in a map."
[m]
(if (seq m)
(reduce comp (map key-renamer m))
identity))
(def rename-keys-transformer
(mt/transformer
{:decoders
{:map
{:compile
(fn [schema _]
(-> schema m/properties :rename -compile-rename-keys-transformer))}}}))
(comment
(m/decode
[:map
{:rename {:a :b :c :d :x :y}}
[:b int?]
[:c int?]
[:y int?]]
{:a 1
:c 2
:x 3}
(mt/transformer rename-keys-transformer)))
Given that an input is incorrect post transformation, how do I report the original field name as invalid?had time to look at this. Thing is, you should describe the resulting schema, not the orginal.
so, it should be:
[:map
{:rename {:a :b, :c :d, :x :y}}
[:b int?]
[:d int?]
[:y int?]]
The problem is that schemas, being a description of "ought", can't report back errors about "is" for any lossy transformation
Anyway, schema validates b, user gave me a, I want to report back "a should be an integer" if I was given a, even thought I treat it as b. Some sort of alias mechanism
(def Target
(m/schema
[:map
[:b int?]
[:d int?]
[:y int?]]))
(def mappings {:b :a, :d :c, :y :x})
(def Source
(mu/transform-entries
Target
(partial map (fn [[k p v]] [(mappings k k) p v]))))
Source
; => [:map [:a int?] [:c int?] [:x int?]]
I would like to see someone cook Meander and Malli together, so that one could write a Malli schema and a Meander transformation for it and infer the target Malli schema from those.
Regarding meander, I also thought on using it for the complex unification problems I made for myself
Add a "match" property to schema which binds, then compile that to meander pattern and match on it

What is the best way to setup the schema to work with a protocol? We could potentially use the https://github.com/metosin/malli#fn-schemas to work through instance?
, but maybe there’s a better solution
Thanks. We’ll probably implement some fn schema to check for satisfies
or instance
for now I guess!
It is not clear to me what is going on here… its stumped me…
(comment
(require '[malli.core :as m]
'[malli.util :as mu])
(def zip
[:re #"\d{5}"])
(def some-schema
[:map
[:zipcode zip]])
(m/validate some-schema {:zipcode "12345\t22"}) => true
(m/validate (mu/merge some-schema nil) "12345\t22") => false
some-schema => [:map [:zipcode [:re #"\d{5}"]]]
(mu/merge some-schema nil) => [:map [:zipcode [:re #"\d{5}"]]]
)
doh’ i mean the obvious here is wrong…one sec..
(being the map in one call and string in another) lol…
I compounded a couple of issues but I dont think its Malli…. I think it might be coercion from reitit. Sorry bout that, another pair of eyes found the painfully obvious string where a map should have been in my example 😐
yeah no issue… happy monday
Bump / help?