Clojure - Sequences take-last

Takes the last list of elements from the sequence.


Following is the syntax.

(take-last num seq1)

Parameters − ‘seq1’ is the sequence list of elements. ‘num’ is the number of elements which needs to be included in the sequence from the end.

Return Value − A new sequence of elements with only the end number of elements included.


Following is an example of take-last in Clojure.

(ns clojure.examples.example

;; This program displays Hello World
(defn Example []
   (def seq1 (seq [5 4 3 2 1]))
   (def seq2 (take-last 2 seq1))
   (println seq2))


The above program produces the following output.

(2 1)
Kickstart Your Career

Get certified by completing the course

Get Started