Skip to content

Instantly share code, notes, and snippets.

@senior
Created April 26, 2012 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senior/8a5125e7827abfbeb8d0 to your computer and use it in GitHub Desktop.
Save senior/8a5125e7827abfbeb8d0 to your computer and use it in GitHub Desktop.
Big lazy-seq in a defrecord
(defrecord Element [tag attrs content]
Emit
(emit-element [e writer] ;;<---- e has a big lazy seq for it's :content, see below
(let [nspace (namespace (:tag e))
qname (name (:tag e))
^javax.xml.stream.XMLStreamWriter writer writer]
(.writeStartElement writer "" qname (or nspace ""))
(write-attributes e writer)
(doseq [c (:content e)]
(emit-element c writer))
(.writeEndElement writer))))
(Element. :some-tags
{}
(map #(Element. :foo {} [(str "foo" %)]) ;;<--- this is the :content of the tag, 10 million <foo>fooX</foo>
(range 0 10000000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment