19

As a newcomer to Clojurescript it appears to me that every Clojurescript project will have some snippet of code like this:

(extend-type js/NodeList
  ISeqable
  (-seq [array] (array-seq array 0)))

Why isn't this part of the core library?

expez
  • 289
  • 2
  • 6
  • 1
    As @Joaquin comments, this is a platform specific adapter issue. Are you familiar with extend-type meanings http://clojuredocs.org/clojure_core/clojure.core/extend-type ? – tangrammer May 13 '14 at 09:15
  • 1
    @expez: I share your surprise that NodeList and HTMLCollection are not automatically usable by standard Clojurescript iterators. Everyone learning Clojurescript should not have to stumble over this, hunt for the answer, and them re-implement boiler plate solution code. – devdanke Dec 27 '15 at 17:18

3 Answers3

13

You have to think that clojurescript is a compiler to javascript as a language, not only browser JavaScript. You can also use it in other platforms like nodejs or with the QT library where NodeList does not exist (because it is part of the Dom api and not the standard language).

Joaquin
  • 2,714
  • 20
  • 19
3

If you are looking for a way to create a sequence from a NodeList there is array-seq function.

(array-seq (js/document.querySelectorAll "div"))
Aliaksandr Sushkevich
  • 11,550
  • 7
  • 37
  • 44
3

With a patch for https://clojure.atlassian.net/browse/CLJS-3199 applied in ClojureScript 1.10.741 (seq (js/document.querySelectorAll "div")) now actually works out of the box.

Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149