Clojure – Sequences drop

Clojure sequences drop

In this guide, we will discuss Clojure Sequences drop. Drops elements from a sequence based on the number of elements, which needs to be removed.

Syntax

Following is the syntax.

(drop num seq1)

Parameters − ‘seq1’ is the sequence list of elements. ‘num’ is the number of elements which need to be dropped.

Return Value − Returns the sequence of elements with the required elements dropped from the sequence.

Example

Following is an example of drop 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 (drop 2 seq1))
   (println seq2))
(Example)

Output

The above program produces the following output.

(3 2 1)

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply