261 def __next__( self ):
262 """Function implementing the recursive iteration over an AlgSequence
263
264 This is where most of the logic is. The iterator loops over the
265 elements of the AlgSequence that was given to it, one by one. When
266 it finds an element in the AlgSequence that itself is also an
267 AlgSequence, then it creates a helper iterator object that would
268 process that sub-sequence, and continue the iteration using that
269 helper.
270
271 The end result is that the iteration should loop over every
272 algorithm in the sequence and its sub-sequences.
273 """
274
275
276 if self._index >= len( self._sequence ):
277 raise StopIteration()
278
279
280
281 if self._iterator:
282 try:
283 return self._iterator.__next__()
284 except StopIteration:
285
286
287
288 self._index += 1
289 self._iterator = None
290 return self.__next__()
291 pass
292
293
294
295 element = self._sequence[ self._index ]
296
297
298
299 if isinstance( element, AlgSequence ):
300 self._iterator = AlgSequenceIterator( element )
301 return self.__next__()
302
303
304
305 self._index += 1
306 return element
307