def graphVisit(node, visitor):
    """Visits the specified node.  The visitor is a callable
    that accepts a node and returns a list of additional
    nodes to visit, if any.

    Each node is guaranteed to be visited at most one
    time in order to prevent cycles, regardless of how
    many times it is in the node list returned by the visitor.

    """
    nodesVisited = set()
    def visit(node):
        if node in nodesVisited:
            return []
        nodesVisited.add(node)
        for n in visitor(node):
            visit(n)
    visit(node)