def METHOD_NAME(nodes: List[NodeType], direction: str = 'FORWARD') -> Generator[NodeType]:
    """
    Walk from the current node, it will visit all next nodes in FORWARD of BACKWARD direction
    First will be visited first child and its children then second child and etc
    """
    # https://en.wikipedia.org/wiki/Depth-first_search
    stack = nodes
    visited = set()
    safe_counter = count()
    max_node_number = 20000
    while stack:
        current_node = stack.pop()
        yield current_node
        visited.add(current_node)
        for next_node in current_node.next_nodes if direction == 'FORWARD' else current_node.last_nodes:
            if next_node not in visited:
                stack.append(next_node)
        if next(safe_counter) > max_node_number:
            raise RecursionError(f'The tree has either more then={max_node_number} nodes '
                                 f'or most likely it is circular')