Clojure - Sequences split-at


Advertisements

Splits the sequence of items into two parts. A location is specified at which the split should happen.

Syntax

Following is the syntax.

(split-at num seq1)

Parameters − ‘seq1’ is the sequence list of elements. ‘num’ is the index position at which the split should happen.

Return Value − Two sequence of elements which are split based on the location where the split should happen.

Example

Following is an example of split-at in Clojure.

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

;; This program displays Hello World
(defn Example []
   (def seq1 (seq [5 4 3 2 1]))
   (println (split-at 2 seq1)))
(Example)

Output

The above program produces the following output.

[(5 4) (3 2 1)]
clojure_sequences.htm
Advertisements