Fork me on GitHub
#malli
<
2021-10-02
>
respatialized14:10:03

Is there an option for m/parse that disables returning tagged values for :orn / :altn / :multi / etc?

ikitommi15:10:36

currently, no. What is your use case for this?

ikitommi15:10:42

if you want to disable all, just call validate and return the original value in case of success ..

respatialized15:10:03

I have a large, complex schema that implements a https://github.com/fabricate-site/fabricate/blob/c04afeb0ab40b49f1f95bde126333992b25ae644/src/site/fabricate/prototype/html.clj#L150 for Hiccup elements. I leverage :orn throughout to preserve contextual information about elements (such as whether they're flow content or phrasing content). This is what it looks like when using a parser to parse a small element:

(site.fabricate.prototype.html/parse-element [:p "text" [:em "with emphasis"]])
=>
[:flow
 [:p
  {:tag :p,
   :attrs nil,
   :contents
   [[:atomic-element [:text "text"]]
    [:node
     [:em
      {:tag :em,
       :attrs nil,
       :contents [[:atomic-element [:text "with emphasis"]]]}]]]}]]
While this contextual information is sometimes useful, I also want the option of returning parsed values without it: just the {:tag t :attrs {} :contents [...]} structure so that every result from m/parse is returned in a uniform way. Perhaps, as you suggest, I'm relying too heavily on m/parse here; there's not much stopping me from pattern matching on the head & tail of the actual elements (so long as they validate) using ordinary sequence functions.

respatialized15:10:22

just as an aside, the fact that it's possible and performant to implement this much contextual information using seqexes speaks to the expressive power of malli. 🔥

respatialized16:10:51

after rewriting the schema manually, I think I was confused about how tagged entries work. if tagging were disabled for the schema, then I wouldn't even get the map syntax from the result.

respatialized16:10:53

my intended result was a mixture of tagged and untagged parse results, so it wouldn't even have been achieved by disabling tagging for :orn.