First, Rest, and Cons

#clojure #language #programming

It is the main principal operations of all sequences in Clojure language. The Seq Operations is composed by

  • First: Get the current value of a node
  • Rest: Get the remaining values of the nodes
  • Cons: Adding a node with a new value on the beginning of the sequence

Seq always a return a value that looks and behaves like a list. Seq of map is a list of vectors

The following code return a map function for JavaScript.

var map = function(list, transform)
	if (list == null){
		return null;
	} else {
		return const (transform (first(list)), map (rest(list), transform));
	}
Links to this page
  • Sequence Abstraction

    Sequence: Set of elements linearly ordered Everything is a sequence can treat as sequence. This is the principal philosophical statement behind Clojure language programming. It is possible to apply map and reduce in a sequence because it is composed by three different operations: First, Rest, and Cons. Is it possible to call seq operations is used by Clojure Seq Functions. All data abstractions in Clojure can be transformed into sequence if it has the following operation above.

#clojure #language #programming