Skip to content

Commit

Permalink
nth should only work ISeq not on ISeqable
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Aug 7, 2013
1 parent d19cc6c commit a113b08
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cljs/cljs/core.cljs
Expand Up @@ -115,6 +115,11 @@
(.join (array "No protocol method " proto
" defined for type " ty ": " obj) ""))))

(defn type->str [ty]
(if-let [s (.-cljs$lang$ctorStr ty)]
s
(str ty)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; arrays ;;;;;;;;;;;;;;;;

(defn aclone
Expand Down Expand Up @@ -901,7 +906,12 @@ reduces them without incurring seq initialization"
(-nth coll n)

:else
(linear-traversal-nth coll (.floor js/Math n)))))
(if (satisfies? ISeq coll)
(linear-traversal-nth coll (.floor js/Math n))
(throw
(js/Error.
(str "nth not supported on this type "
(type->str (type coll)))))))))
([coll n not-found]
(if-not (nil? coll)
(cond
Expand All @@ -922,7 +932,12 @@ reduces them without incurring seq initialization"
(-nth coll n)

:else
(linear-traversal-nth coll (.floor js/Math n) not-found))
(if (satisfies? ISeq coll)
(linear-traversal-nth coll (.floor js/Math n) not-found)
(throw
(js/Error.
(str "nth not supported on this type "
(type->str (type coll)))))))
not-found)))

(defn get
Expand Down

0 comments on commit a113b08

Please sign in to comment.