Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

nth should only work ISeq not on ISeqable

  • Loading branch information...
commit a113b08a8c2811b0590cc6a36b2e9e5adc1c4c1e 1 parent d19cc6c
@swannodette swannodette authored
Showing with 17 additions and 2 deletions.
  1. +17 −2 src/cljs/cljs/core.cljs
View
19 src/cljs/cljs/core.cljs
@@ -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
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.