This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-18
Channels
- # beginners (56)
- # boot (1)
- # cider (96)
- # cljs-dev (148)
- # clojure (60)
- # clojure-austin (11)
- # clojure-france (2)
- # clojure-italy (5)
- # clojure-russia (11)
- # clojure-spec (31)
- # clojure-uk (5)
- # clojurescript (52)
- # community-development (37)
- # cursive (3)
- # data-science (8)
- # datomic (14)
- # devcards (2)
- # emacs (1)
- # fulcro (13)
- # hoplon (1)
- # immutant (2)
- # luminus (3)
- # off-topic (2)
- # onyx (16)
- # parinfer (38)
- # re-frame (8)
- # reagent (5)
- # shadow-cljs (332)
- # spacemacs (5)
- # specter (5)
- # sql (6)
- # vim (52)
Hi @nathanmarz and all. I'm stuck on a (probably) simple one. I have this xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<book>
<frontmatter/>
<chapter name="Introduction">
<para>Here is the intro</para>
<para>Another paragraph</para>
</chapter>
<chapter name="Conclusion">
<para>All done now</para>
</chapter>
</book>
the Challenge is to get the string content from chapter elements with attr name = "Introduction" ; using thread last
(time (->> [doc]
(mapcat :content)
(filter #(= :chapter (:tag %)))
(filter #(= "Introduction" (get-in % [:attrs :name])))
(mapcat :content)
(filter #(= :para (:tag %)))
(mapcat :content)
(filter string?)))
; transducers and compose
(time (eduction
(comp
(mapcat :content)
(filter (comp (partial = :chapter) :tag))
(filter (comp (partial = "Introduction") :attrs :name))
(mapcat :content)
(filter (comp (partial = :para) :tag))
(mapcat :content)
(filter string?))
[doc]))
; specter: this isn't correct yet...
(select [:content ALL
(filterer :tag #(= % :chapter))
(filterer :attrs :name #(= % "Introduction"))
:content ALL
(filterer :tag #(= % :para))
:content ALL
string?] doc)
@poppetew I think you're looking for selected?
rather than filterer
?
(select [:content
ALL
(selected? :tag (pred= :chapter))
(selected? :attrs :name (pred= "Introduction"))
:content
ALL
(selected? :tag (pred= :para))
:content
ALL
string?]
doc)
pred=
is also slightly nicer than doing #(= % ...)