Skip to content

Commit

Permalink
first, rest rewritten in RT.java style as per David Nolen's idea
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmarczyk committed May 5, 2012
1 parent e227b10 commit cec40f6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/cljs/cljs/core.cljs
Expand Up @@ -500,14 +500,25 @@ 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)))
(if (coercive-not= coll nil)
(if (satisfies? ISeq coll)
(-rest coll)
(let [s (seq coll)]
(if (coercive-not= s nil)
(-rest s)
())))
()))

(defn next
"Returns a seq of the items after the first. Calls seq on its
Expand Down

0 comments on commit cec40f6

Please sign in to comment.