Example 2: Protocols (Domina)

Defining the Protocol
(defprotocol DomContent
  (nodes [content] "Returns the content as a sequence of nodes.")
  (single-node [nodeseq] "Returns the content as a single node"))

Extending Types and Protocols
(extend-protocol DomContent
  string
  (nodes [s] (cons (dom/htmlToDocumentFragment s)))
  (single-node [s] (dom/htmlToDocumentFragment s))

  js/Element
  (nodes [content] (cons content))
  (single-node [content] content)

  default
  (nodes [content] (seq content))
  (single-node [content] (first content)))

(extend-type js/NodeList
  ISeqable
  (-seq [nodelist] (lazy-nodelist nodelist)))