Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in ClojureScript by

I just discovered that JS TypedArrays (Uint8Array et al) do not implement ICounted out of the box, even though it's trivial to make them do so. As a result count doesn't work on them; this is in contrast to Clojure where count works on arrays of primitives. Can/should this be added, or is the current behaviour intended?

(count (js/Uint8Array. [1 2 3]))
;; Execution error (Error) at (<cljs repl>:1).
;; No protocol method ICounted.-count defined for type object: 1,2,3
;=> :repl/exception!

(extend-protocol ICounted
 js/Uint8Array 
 (-count [this] (alength this)))
;=> #object [Function]

(count (js/Uint8Array. [1 2 3]))
;=> 3

Please log in or register to answer this question.

...