Clojure’s reverse
method returns a sequence with its order reversed. A Clojure sequence is a data storage structure that holds a collection of data objects. It can be seen as a logical list. The seq
method builds a sequence.
The code snippet below shows the use of the reverse
method:
(reverse seq1)
The reverse
method accepts one input argument: a Clojure sequence. The input argument in the code snippet above is seq1
. The reverse
method returns a sequence with the same elements as the input sequence but with their order reversed. When the code snippet is executed, it returns a sequence containing all values in seq1
with their order reversed. Let’s look at an example.
(ns clojure.examples.example (:gen-class)) (defn revers [] (def seq1 (seq [1 2 8 9 1 0 6 8 2])) (println (reverse seq1))) (revers)
revers
.seq1
using the seq
method.reverse
method to reverse the order of elements in seq1
and use println
to print the result returned by reverse
.revers
function.RELATED TAGS
CONTRIBUTOR
View all Courses