sequence
?A sequence
is a data storage structure that holds a collection of data objects. In Clojure, it can be seen as a logical list. The seq
method is used to build a sequence.
drop
method in Clojure Sequence?The drop
sequence method will return a sequence with the remaining element after removing a specified number of elements from the beginning of the sequence.
This method can be used to remove elements in a sequence.
(drop number seqq)
This method takes the following parameters:
seqq
: This represents the sequence
containing element.number
: This is the number of elements you wish to remove from the sequence, starting from the first element.This method returns a sequence containing the elements left after the removal.
(ns clojure.examples.example(:gen-class))(defn dropp [](def seq1 (seq [1 2 8 9 1 0 6 8 2]))(println (drop 3 seq1)))(dropp)
dropp
.seq1
.drop
method to remove 3
elements from the sequence because according to the syntax
, we pass the number of elements we want to remove, and in the above example we passed 3
. So, elements 1
, 2
, and 8
will be removed, as we would see in the output.dropp
function, and we observe that the output returned all the elements of the sequence except for the first three elements, which are 1
,2
, and 8
.