Clojure - vector-of


Advertisements

Creates a new vector of a single primitive type ‘t’, where ‘t’ is one of :int :long :float :double :byte :short :char or :boolean. The resulting vector complies with the interface of vectors in general, but stores the values unboxed internally.

Syntax

Following is the syntax.

(vector-of t setofelements)

Parameters − ‘t’ is the type which the vector elements should be. ‘Setofelements’ is the set of elements comprised in the vector.

Return Value − The vector set of elements of the required type.

Example

Following is an example of vector-of in Clojure.

(ns clojure.examples.example
   (:require [clojure.set :as set])
   (:gen-class))
(defn example []
   (println (vector-of :int 1 2 3)))
(example)

Output

The above code produces the following output.

[1 2 3]
clojure_vectors.htm
Advertisements