In Clojure, take keeps the first n elements of a sequential input and discards the remainder. It is useful for limiting a sequence, inspecting a prefix, or selecting a record’s leading fields. section 10.2
The function supports both ordinary sequence processing and transducer composition:
- (take n coll) returns a sequence containing at most the first n elements. section 10.2
- (take n) returns a transducer that keeps the prefix and terminates reduction after n elements. section 7.2
- n may be positive, zero, negative, integer, or floating-point; negative values behave like zero, and coll may be nil or any seqable input. section 10.2
- A non-sequential coll violates the sequence contract and raises IllegalArgumentException. section 10.2
Selecting leading fields
Taking the first three values from each HTTP log record makes its status code, day, and month available for filtering: (let [[code _ month] (take 3 record)] ...). Applied to the sample messages, this identifies the three March errors.
Composing a transducer
When the collection argument is omitted, take composes with other transformations: (transduce (comp (drop 3) (map inc) (take 4)) + (range 10)) processes only the selected prefix after dropping three items and incrementing values. section 7.2
Table 10.2. A summary of the functions available to extract a portion of a sequence.
| Name |
Description |
Transducible? |
Fully lazy? |
| Drops the first n elements. |
Yes |
Yes |
|
| Drops items until the given predicate returns |
Yes |
Yes |
|
| Drops the last n elements (default to 1). |
No |
Yes |
|
| Keeps the first n elements, drops the rest. |
Yes |
Yes |
|
| Keeps element until the given predicate returns |
Yes |
Yes |
|
| Keeps the last n elements (no default for n). |
No |
No |
|
| Like |
No |
No |
|
| Like |
No |
No |
The comparison table places take among sequential selectors, contrasting its prefix-preserving behavior, transducer support, and full laziness with related functions. section 10.2



