In this guide, we will discuss Clojure Sequences take. Takes the first list of elements from the sequence.
Syntax
Following is the syntax.
(take 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 beginning.
Return Value − A new sequence of elements with only the beginning number of elements included.
Example
Following is an example of take in Clojure.
(ns clojure.examples.example (:gen-class)) ;; This program displays Hello World (defn Example [] (def seq1 (seq [5 4 3 2 1])) (def seq2 (take 2 seq1)) (println seq2)) (Example)
Output
The above program produces the following output.
(5 4)
Next Topic : Click Here
Pingback: Clojure - Sequences take-last | Adglob Infosystem Pvt Ltd
Pingback: Clojure - Sequences | Adglob Infosystem Pvt Ltd