take-last returns a sequence containing the specified number of elements from the end of a sequential input. The count argument is required; zero or negative counts behave like zero. Unlike take, take-last has no transducer form and is not fully lazy. section 10.2
Use take-last when selection should keep the tail rather than the head:
- Pair it with take to retain the final portion of a bounded prefix. section 10.2
- Contrast it with drop-last, which removes the tail while retaining the head. section 10.2
- Expect a sequential result; a non-sequential input raises IllegalArgumentException. section 10.2
Evaluation of a lazy source
Applying (take-last 1 (take 10 (xs))) to a source that prints a dot for each realized element prints ten dots before returning. The operation therefore evaluates the bounded input rather than behaving as a fully lazy head selector. section 10.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 |
Compare take-last with neighboring sequence-selection functions by direction, transducibility, and laziness. section 10.2
