 The standard library contains many functions for working with sequences. Most of these functions will invoke seek on a seekable argument, so you can generally pass them seekable types, like vectors, without having to explicitly invoke seek yourself. Here we'll describe some of the most essential sequence functions. The next function is like rest, but returns nil for sequences of zero or more elements. The nth function is like get, but works on sequences. The apply function invokes a function with arguments taken from a sequence. The map function returns a lazy sequence produced by invoking a function with arguments from other sequences. The reduce function returns the result of invoking a function on successive pairs of elements in a sequence, and the reductions function returns a lazy sequence of the intermediate values that would be produced by reduce. So looking at some examples, this first call to next returns a sequence of three four, just like rest would, but these second and third calls return nil rather than an empty sequence. This first call to nth works just like get, returning the element index three of the vector. Understand however that nth requires a linear traversal of the sequence, so when accessing elements of vectors, it is generally much faster to use get instead of nth. The second call to nth demonstrates that unlike get, nth works on all sequences, not just vectors. The third call to nth demonstrates that unlike get, nth throws an exception with the indexes out of bounds rather than return nil. In the fourth call however, we supply a default value to return when the index is out of bounds, so this last call to nth returns the string high. The first call to apply returns the value of the plus function invoked with the elements of the vector as its arguments, and so this call returns 15. The stir function returns the string concatenation of its arguments, and so the second call to apply returns yoho. In the third call to apply, we pass additional arguments before the sequence, so stir has passed four arguments high by yo and ho, and so returns the string high by yoho. This first call to map returns a lazy sequence produced by invoking the plus function with a single argument taken from each sequence in order until the shortest sequence is exhausted, so the lazy sequence calls plus with the arguments 1 and 7, then 2 and 8, then lastly 3 and 9. This second call to map returns a lazy sequence produced by invoking the multiplication function with the arguments 1, 7, and 3, then lastly 2, 8, and negative 1. This call to reduce returns a single value by applying the plus function to the first two elements of the sequence, then applying it with that result and the third element, then lastly applying it with that result and the fourth element, so it effectively adds 1 to 2 to 3 to 4. When called with three arguments, the second argument to reduce is treated as if it is the first element of the sequence, so the second call returns 30. This first call to reductions returns a lazy sequence of the first element of the sequence, and then all the intermediate values of applying the plus function on successive pairs of the sequence, so first 1, then 1 and 2 returning 3, then 3 and 3 returning 6, then lastly 6 and 4 returning 10. The second call to reduction starts with 20, then 20 and 1 returning 21, then 21 and 2 returning 23, then 23 and 3 returning 26, then lastly 26 and 4 returning 30. Looking at yet more sequence functions, the filter function returns a lazy sequence containing the elements of another sequence for which a conditioned function returns true. The remove function is like filter, but returns a sequence with the elements for which the conditioned function returns false rather than true. The take function returns a lazy sequence of the first n elements of a sequence, take last returns a lazy sequence of the last n elements of a sequence, and take nth returns a lazy sequence of every nth element of a sequence. The concat function returns a lazy sequence that concatenates and order the elements of multiple sequences. So looking at examples, this first call to filter uses the even function to select elements from the vector. The even function returns true when its argument is even, so the returned lazy sequence has the values 6, 4, 22, and negative 6. The second call to filter uses the odd function instead, so this call returns a lazy sequence with the values 1, 3, 23, and negative 5. These two calls to remove demonstrate that remove selects the inverse of filter. This call to take returns a lazy sequence of the first three elements of the vector, 1, 3, and 6. The call to take last returns a lazy sequence of the last three elements of the vector, 23, negative 6, and negative 5. The call to take int returns every third element from the vector starting with the first, and so returns 1, 4, and negative 6. This call to concat returns a lazy sequence with all the elements of the sequence arguments in order of appearance, 1, 2, 3, 4, 5, and 6. Here are the last six functions we'll discuss for the moment. The interleave function returns a lazy sequence that takes elements from multiple collections around Robin. The interpose function returns a lazy sequence in which a value is inserted in between elements of a sequence. The distinct function returns a lazy sequence in which only the first occurrences of any value is retained. The reverse function returns a list of the elements of a sequence in reverse order. The flattened function returns a lazy sequence containing the elements of some other sequence and any nested sequences. And lastly, the sort function returns a non-lazy sequence of the elements of some other sequence in sorted order. So here, this call to interleave returns a lazy sequence of the elements of the sequence arguments in round Robin order until the shortest sequence argument is exhausted. So we get 1, 5, 9, 2, 6, and 10. This call to interpose returns a lazy sequence with a value of 3 inserted in between every element of the vector, so we get 7, 3, 8, 3, 9, 3, and 10. This call to distinct returns a lazy sequence that retains only the first occurrence of each value in the vector, so we get 1, 4, 2, and 3. The call to reverse returns a list, not a lazy sequence, of the vector's elements in reverse order, so we get 3, 2, and 1. The flattened function returns a lazy sequence of all the values of the vector in order, even those nested within other vectors. Lastly the sort function returns a non-lazy sequence of the vector's elements in sorted order. By default, sort uses the compare function to decide what values come before what. The compare function returns negative 1 when its first argument is lesser than its second, plus 1 when its first argument is greater than its second, and 0 when its two arguments are equal. We can customize the sorting behavior of sort by providing a substitute function for compare. This substitute function must either also return negative 1 plus 1 or 0, or otherwise it must return true or false. In this last example we call sort, but provide the greater than function as a substitute for compare. The greater than function returns true when its first argument is greater than its second, and so this call to sort returns the numbers in order of greatest to least value.