take

functionsince v0.0-927 clojure.core/takeEdit
(take n)
(take n coll)

Details:

Returns a lazy sequence of the first n items in coll. Returns all the items if there are fewer than n.

Returns a stateful transducer when no collection is provided.


See Also:


Source docstring:
Returns a lazy sequence of the first n items in coll, or all items if
there are fewer than n.  Returns a stateful transducer when
no collection is provided.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn take
  ([n]
   {:pre [(number? n)]}
     (fn [rf]
       (let [na (volatile! n)]
         (fn
           ([] (rf))
           ([result] (rf result))
           ([result input]
              (let [n @na
                    nn (vswap! na dec)
                    result (if (pos? n)
                             (rf result input)
                             result)]
                (if (not (pos? nn))
                  (ensure-reduced result)
                  result)))))))
  ([n coll]
   {:pre [(number? n)]}
     (lazy-seq
       (when (pos? n)
         (when-let [s (seq coll)]
           (cons (first s) (take (dec n) (rest s))))))))