cycle_detector.py
def naive(seqs, f=None, start=None, key=lambda x: x):
    """Naive cycle detector

    See help(cycle_detector) for more context.

    Args:

      sequence: A sequence to detect cyles in.

      f, start: Function and starting state for finite state machine

    Yields: 

      Values yielded by sequence_a if it terminates, undefined if a
      cycle is found.

    Raises:

      CycleFound if exception is found.  Will always generate a first
      and period value no matter which of the `seqs` or `f` interface
      is used.
    """
    history = {}
    for step, value in enumerate(seqs[0]):
        keyed = key(value)
        yield value
        if keyed in history:
            raise CycleDetected(
                first=history[keyed], period=step - history[keyed])
        history[keyed] = step
def naive(seqs, f=None, start=None, key=lambda x: x):
    history = {}
    for step, value in enumerate(seqs[0]):
        keyed = key(value)
        yield value
        if keyed in history:
            raise CycleDetected(
                first=history[keyed], period=step - history[keyed])
        history[keyed] = step
def naive ( seqs , f = None , start = None , key = lambda x : x ) : history = { } for step , value in enumerate ( seqs [ 0 ] ) : keyed = key ( value ) yield value if keyed in history : raise CycleDetected ( first = history [ keyed ] , period = step - history [ keyed ] ) history [ keyed ] = step
Naive cycle detector

    See help(cycle_detector) for more context.

    Args:

      sequence: A sequence to detect cyles in.

      f, start: Function and starting state for finite state machine

    Yields: 

      Values yielded by sequence_a if it terminates, undefined if a
      cycle is found.

    Raises:

      CycleFound if exception is found.  Will always generate a first
      and period value no matter which of the `seqs` or `f` interface
      is used.
Naive cycle detector