function | since v0.0-927 | clojure.core/drop | Edit |
(drop n)
(drop n coll)
Returns a lazy sequence of all but the first n
items in coll
.
Returns a stateful transducer when no collection is provided.
Returns a laziness-preserving sequence of all but the first n items in coll. Returns a stateful transducer when no collection is provided.
(defn drop
([n]
{:pre [(number? n)]}
(fn [rf]
(let [na (volatile! n)]
(fn
([] (rf))
([result] (rf result))
([result input]
(let [n @na]
(vswap! na dec)
(if (pos? n)
result
(rf result input))))))))
([n coll]
{:pre [(number? n)]}
(if (implements? IDrop coll)
(or
(if (pos? n)
(-drop coll (Math/ceil n))
(seq coll))
())
(let [step (fn [n coll]
(let [s (seq coll)]
(if (and (pos? n) s)
(recur (dec n) (rest s))
s)))]
(lazy-seq (step n coll))))))