1.3.0 permalink Arrow_down_16x16
  • (take n coll)
Returns a lazy sequence of the first n items in coll, or all items if
there are fewer than n.

2 Examples top

  • user=> (take 3 '(1 2 3 4 5 6))
    (1 2 3)
    
    user=> (take 3 [1 2 3 4 5 6])
    (1 2 3)
    
    user=> (take 3 [1 2])
    (1 2)
    
    user=> (take 1 [])
    ()
  • user=> (take 3 (drop 5 (range 1 11)))
    (6 7 8)
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2491 top

(defn take
  "Returns a lazy sequence of the first n items in coll, or all items if
  there are fewer than n."
  {:added "1.0"
   :static true}
  [n coll]
  (lazy-seq
   (when (pos? n) 
     (when-let [s (seq coll)]
      (cons (first s) (take (dec n) (rest s)))))))
Vars in clojure.core/take:
Used in 0 other vars

Comments top

No comments for take. Log in to add a comment.