Permalink
Browse files

first, rest rewritten in RT.java style as per David Nolen's idea

  • Loading branch information...
michalmarczyk committed May 3, 2012
1 parent 2d2f11f commit c92236ee3f93dc3cb430f635017c3245199afd3c
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/cljs/cljs/core.cljs
View
@@ -500,14 +500,23 @@ reduces them without incurring seq initialization"
"Returns the first item in the collection. Calls seq on its
argument. If coll is nil, returns nil."
[coll]
- (when-let [s (seq coll)]
- (-first s)))
+ (when (coercive-not= coll nil)
+ (if (satisfies? ISeq coll)
+ (-first coll)
+ (let [s (seq coll)]
+ (when (coercive-not= s nil)
+ (-first s))))))
(defn rest
"Returns a possibly empty seq of the items after the first. Calls seq on its
argument."
[coll]
- (-rest (seq coll)))
+ (when (coercive-not= coll nil)
+ (if (satisfies? ISeq coll)
+ (-rest coll)
+ (let [s (seq coll)]
+ (when (coercive-not= s nil)
+ (-rest s))))))
(defn next
"Returns a seq of the items after the first. Calls seq on its

0 comments on commit c92236e

Please sign in to comment.