Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't NodeList / HtmlCollection seqable?

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?

like image 260
expez Avatar asked May 12 '14 18:05

expez


3 Answers

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).

like image 143
Joaquin Avatar answered Jan 17 '23 01:01

Joaquin


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"))
like image 24
Aliaksandr Sushkevich Avatar answered Jan 17 '23 01:01

Aliaksandr Sushkevich


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.

like image 43
Michiel Borkent Avatar answered Jan 17 '23 03:01

Michiel Borkent