The following conditional SequenceIterator methods apply the object's
boolean
sequence to the input sequence(s). These methods are of the following types:
- Ternary operation iif() which takes two input sequence arguments then and otherwise, and produces a result sequence of the same type by applying the
boolean
element in the object's condition sequence.- filter() which returns a sequence of the same type as input with only the elements corresponding to
true
elements in the object's condition sequence- filter_pos() which returns an integer sequence with the positions of the
true
elements in the object's condition sequenceThe operation can be one of the following:
public SequenceIterator iif(SequenceIterator then, SequenceIterator otherwise, boolean lazy)
Choose the element of the then sequence or the otherwise sequence depending on the boolean value of the element of the object's condition sequence. All three sequences are traversed at the same speed (if the element of the then sequence is used, then the element of otherwise sequence is skipped and visa versa). (Please see the Ternary Operations page for further details.)
public SequenceIterator filter(SequenceIterator cond)
Returns a sequence of the same type as input with only the elements corresponding to
true
elements in the object's condition sequencepublic SequenceIterator filterPos()
Returns an integer sequence with the positions of the
true
elements in the object's condition sequenceExample
Following is an example code snippet demonstrating a conditional method:
cursor = con.cursor("Quote", "by_sym") for quote in cursor: ... last = quote.day.last(); dayit = quote.day.search(DMY(1,MONTH(last),YEAR(last)), exdb.SeqIteratorBoundary.MCO_SEQ_BOUNDARY_INCLUSIVE, last, exdb.SeqIteratorBoundary.MCO_SEQ_BOUNDARY_INCLUSIVE) openit,closeit = dayit.project('open', 'close') gtit = closeit.gt(openit) filtit = gtit.filter(dayit) ...