Conditional Sequence Operations in C#

Conditional sequence methods apply Boolean sequence results to choose values, filter rows, or locate matching positions.

In the C# API, analytics operate on Sequence values obtained from OrderedSequence<T> searches, direct ordered-sequence iteration, UnorderedSequence<T>.All, or positional projections such as quote.Close[dayRange].

For an overview see page The C# Sequence Class

Operations

condition.If(thenSequence, otherwiseSequence, bool lazy)
Returns a sequence that selects values from thenSequence or otherwiseSequence based on each Boolean element.
source.Filter(condition)
Returns only the elements of source whose corresponding condition element is true.
condition.FilterPos()
Returns the positions of the elements where the Boolean condition is true.

Example

The C# samples use Filter to keep only the days where the close price is greater than the open price.

    using (Sequence dayRange = quote.Day.Search(20130101u, SelectBoundary.Inclusive,
                                                20130401u, SelectBoundary.Inclusive))
    {
        PrintIntSequence(quote, dayRange.Filter(quote.Close[dayRange] > quote.Open[dayRange]));
    }