# Manipulator C++ Sequence Methods

> The following manipulator C++ Sequence methods take a variety of sequence arguments and produce result sequences as described in the table below:

> Sequence<T> reverse() const | Reverse the elements of the input sequence.
> Sequence<T> concat(Sequence<T> const& other) const also operator,(Sequence<T> const& other) const | Concatenate two sequences of any type by appending sequence right to sequence left. The result sequence will be of the same type as left and right.
> Sequence<T> limit(mco_seq_no_t from, mco_seq_no_t till) const also Sequence<T> operator()(mco_seq_no_t from, mco_seq_no_t till) const | Copy to the result sequence the sub-sequence from the input using sequence positions from and till.
> void get(std::vector<T>& result) | Extract data from the input sequence to the buffer result
> Sequence<T> unique() const | Copy to the result sequence only the unique elements in ordered sequence input by "collapsing duplicates".
> Sequence<double> norm() const | Return in result the normalized input sequence; i.e. divide each sequence element by the square root of the sum of squares of all elements.
> Sequence<T> thin(mco_size_t origin, mco_size_t step) const | Copy the input sequence to result selecting elements with the specified origin and step.
> Sequence<T> diff() const | Return in result the differences between pairs of sequence elements in input.
> Sequence<T> combine(Sequence<T> const& other, mco_seq_order_t order) const | Return in result the union of the two ordered sequences left and right using the specified order. Note that result will contain different elements from both input sequences.
> Sequence<T> map(Sequence<mco_seq_no_t> const& positions) const also Sequence<T> operator[](Sequence<mco_seq_no_t> const& positions) const | Return in result the elements extracted from the input sequence using the positions specified in the positions sequence. The positions should be provided in ascending order.
> Sequence<T> repeat(int nTimes) const | Return in result each element of the input sequence repeated n_times times.
> Sequence<T> stretch(Sequence<TS> const& ts1, Sequence<TS> const& ts2, T filler) const | Return in result the elements of the values sequence stretched to the length of the ts1 sequence by repeating the elements of values while the corresponding timestamp in sequence ts2 is larger than timestamp from ts1. Use the filler values for elements where the corresponding timestamp in sequence ts2 is less than timestamp from ts1. For example, assume ts1 = `{1,2,3,4,5}`, ts2 = `{2,4}`, values = `{1.1,2.2}` and filler =`1.0`. With these input sequences the result will be `{1.1,2.2,2.2,1.0,1.0}`. (This method can be used to calculate split adjusted price where it is necessary to revert time series of splits, calculate the cumulative product and multiply on price.)
> Sequence<T> stretch0(Sequence<TS> const& ts1, Sequence<TS> const& ts2, T filler) const | Return in result the elements of the values and filler sequences by injecting the elements of values where the corresponding timestamps in sequence ts2 match the timestamp from ts1. Use the filler values for elements where the timestamp in sequence ts2 has no matching timestamp in ts1. For example, assume ts1 = `{1,2,3,5}`, ts2 = `{2,3,4}`, values = `{1.1,1.2,1.3}` and filler = `0.0`. With these input sequences the result will be `{0.0,1.1,1.2,1.3,0.0}`.
> Sequence<T> asofJoin(Sequence<TS> const& ts1, Sequence<TS> const& ts2) const | Return in result the elements of the values sequence corresponding to the timestamp of ts2 closest to the timestamp of ts1. For example, assume ts1 = `{4,9}`, ts2 = `{1,3,6,10}`, and values = `{0.1,0.3,0.6,1.0}`. With these input sequences the result will be `{0.3,1.0}`.
> Sequence<mco_seq_no_t> cross(int first_cross_direction) const | Return in result the positions in the input sequence where it crosses zero. If the integer argument first_cross_direction is positive then the result sequence starts with the first cross above zero; if negative it starts with cross below zero; if first_cross_direction is zero then it doesn't matter, i.e. the first cross can be above or below zero.
> Sequence<mco_seq_no_t> extrema(int first_extremum) const | Return in result the positions of extrema (local minimum and maximums) in the input sequence. If the integer argument first_extremum is positive then the result sequence starts with first local maximum; if negative it starts with with local minimum; if first_extremum is zero then it doesn't matter.

> ## Example

> Following is an example code snippet demonstrating a sequence manipulator function:

>         {
>             mco_trans_h trans;
>             mco_cursor_t quote_cursor;
>             Quote quote;
>             MCO_RET rc;
>             ...
>             rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans);
>             if ( MCO_S_OK == rc )
>             {

>                 for (rc = mco_cursor_first(trans, &quote_cursor);
>                     rc != MCO_S_CURSOR_END;
>                     rc = mco_cursor_next(trans, &quote_cursor))
>                 {
>                     quote.from.cursor(trans, &quote_cursor);

>                     // Calculate window (moving) aggregates. Find the dates
>                     // when the 20-day moving average crosses over the
>                     // 5-days moving average
>                     print_sequence(quote, quote.day_map(
>                         (quote.close_iterator().windowAggAvg(20) -
>                         quote.close_iterator().windowAggAvg(5)).cross(1)));
>                 }
>                 mco_trans_rollback(trans);
>             }
>         }