Clojure - Sequences first



Returns the first element of the sequence.

Syntax

Following is the syntax.

(first seq1)

Parameters − ‘seq1’ is the sequence list of elements.

Return Value − The first element of the sequence is returned.

Example

Following is an example of first in Clojure.

(ns clojure.examples.example
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def seq1 (seq [1 2 3]))
   (println (first seq1)))
(Example)

Output

The above program produces the following output.

1
clojure_sequences.htm
Advertisements