Closed maxfischer2781 closed 7 years ago
Now using a StopTraversal
exception. Only downside is that n->1
and 1->1
generators cannot stop traversal.
There is still some unclear semantics for stopping inside a nested chain with return value.
Current approach seems to work well enough in practice. Lack of generator/coroutine support is unfortunate, but class based approaches work well as replacements.
Stop+return in nested chains seems ambiguous either way. Staying with the current approach, which is the most efficient. Whether to advance or not can be influenced by putting later elements into the nested or enclosing chain.
With separate Chains and Links, there is currently no way for a Link to signal an end of chain traversal. This makes filters impossible, and thus makes future loops questionable.
There are two situations for aborting the traversal of a chain:
StopIteration
is appropriate.StopIteration
if there are no more subchains.StopTraversal
, is suggested.send
and__next__
, since this is used by external iteration. It uses traversal, but filters out any internal exceptions.visit(value=None)
, or a conventionalchain_*
(chain_send
),link_*
,c*
.