This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-02
Channels
- # announcements (15)
- # aws-lambda (1)
- # babashka (2)
- # beginners (25)
- # calva (2)
- # cider (6)
- # cljfx (6)
- # clojure (24)
- # clojure-boston (1)
- # clojure-dev (2)
- # clojure-europe (31)
- # clojure-uk (2)
- # clojurescript (48)
- # community-development (4)
- # conjure (1)
- # datahike (4)
- # datascript (10)
- # datomic (1)
- # deps-new (1)
- # fulcro (10)
- # juxt (1)
- # malli (7)
- # missionary (1)
- # nrepl (2)
- # off-topic (2)
- # other-languages (5)
- # polylith (4)
- # random (1)
- # react (2)
- # shadow-cljs (9)
- # tools-deps (21)
Is there an option for m/parse
that disables returning tagged values for :orn
/ :altn
/ :multi
/ etc?
if you want to disable all, just call validate and return the original value in case of success ..
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.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
. 🔥
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.
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
.