Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

clojure
list method
communitycreator

What is the rest list method in Clojure?

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

A list is a data storage structure that holds a collection of data objects. The list method in Clojure is used to build lists.

What is the rest list method in Clojure?

The rest method is a list method that returns all the items in a list except the first element.

Syntax

(rest lst)
The rest method in Clojure

Parameter

The rest method receives a list represented by lst in the syntax.

Return value

The rest method returns the list of items without the first item of the passed list. Let's see an example to understand this further.

Example

(ns clojure.examples.example
(:gen-class))
(defn restlist []
(println (rest (list 1 2,40,80,12,34))))
(restlist)
The rest method of a list in Clojure

Code explanation

In the code above:

  • In line 3, we create a function restlist
  • In line 4, we print the output of the rest method using the println, and pass a list of items to the rest method.
  • In line 5, we call our function restlist.

RELATED TAGS

clojure
list method
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring