Return a pre-order iterator for the tree.
557027
def pre_order(self):
        """"""
        yield self
        for child in self.children:
            for node in child.pre_order():
                yield node
769842
@Override
    public Iterator<Tree> iterator() {
        return new Iterator<Tree>() {
            @Override
            public boolean hasNext() {
                return next != null;
            }

            @Override
            public Tree next() {
                Tree t = next.leaf;
                next = next.parent;
                return t;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }

            private TreePath next = TreePath.this;
        };
    }
218089
def iteritems(self):
        """"""
        if self.type in ['blob']:
            raise StopIteration

        for path, mode, sha in self.tree.iteritems():
            item = Item(self, sha, path, mode)
            yield item
            for i in item.iteritems():
                yield i
602579
def nexson_tree_preorder_iter(tree_proxy, node_id=None, node=None, edge_id=None, edge=None):
    
    tree = tree_proxy._nexson_tree
    ebsid = tree['edgeBySourceId']
    nbid = tree['nodeById']
    if edge_id is not None:
        assert edge is not None
        if node_id is None:
            node_id = edge['@target']
        else:
            assert node_id == edge['@target']
        if node is None:
            node = nbid[node_id]
        else:
            assert node == nbid[node_id]
        yield tree_proxy._create_node_proxy_from_edge(edge_id, edge, node_id=node_id, node=node)
        root_id = node_id
    elif node_id is not None:
        if node is None:
            node = nbid[node_id]
        else:
            assert node == nbid[node_id]
        yield tree_proxy._create_node_proxy_from_edge(None, None, node_id=node_id, node=node)
        root_id = node_id
    else:
        root_id = tree['^ot:rootNodeId']
        root = nbid[root_id]
        yield tree_proxy._create_node_proxy_from_edge(None, None, node_id=root_id, node=root)
    stack = []
    new_stack = [(i['@target'], edge_id, i) for edge_id, i in ebsid[root_id].items()]
    stack.extend(new_stack)
    while stack:
        target_node_id, edge_id, edge = stack.pop()
        node = nbid[target_node_id]
        yield tree_proxy._create_node_proxy_from_edge(edge_id=edge_id, edge=edge, node_id=target_node_id)
        daughter_edges = ebsid.get(target_node_id)
        if daughter_edges is not None:
            new_stack = [(i['@target'], edge_id, i) for edge_id, i in daughter_edges.items()]
            stack.extend(new_stack)
482530
def iter_(obj):
    
    if six.PY2:
        file_types = file,  # noqa
    if six.PY3:
        file_types = io.IOBase,
        dict_items = {}.items().__class__
        dict_values = {}.values().__class__
        dict_keys = {}.keys().__class__
        dict_view = (dict_items, dict_values, dict_keys)

    if isinstance(obj, dict):
        return ordered_sequence_iterator(list(obj.keys()))
    if isinstance(obj, file_types):
        return file_iterator(obj)
    if six.PY2:
        if isinstance(obj, (list, tuple)):
            return ordered_sequence_iterator(obj)
        if isinstance(obj, xrange):  # noqa
            return range_iterator(obj)
        if NUMPY_AVAILABLE and isinstance(obj, numpy.ndarray):
            return ordered_sequence_iterator(obj)
    if six.PY3 and isinstance(obj, dict_view):
        return ordered_sequence_iterator(list(obj))
    return iter(obj)
55584
function Iterator(tree, snapshot) {
  this.tree = tree;
  this.root = snapshot;
  this.current = snapshot;
  this.key = null;
  this.value = null;
}
1276060
def _build_first_tree(self):
        """"""
        tau_sorted = self._sort_tau_by_y(0)
        for itr in range(self.n_nodes - 1):
            ind = int(tau_sorted[itr, 0])
            name, theta = Bivariate.select_copula(self.u_matrix[:, (0, ind)])

            new_edge = Edge(itr, 0, ind, name, theta)
            new_edge.tau = self.tau_matrix[0, ind]
            self.edges.append(new_edge)
1266254
def this_and_prev(iterable):
    """"""
    try:
        item = next(iterable)
        while True:
            next_item = next(iterable)
            yield item, next_item
            item = next_item
    except StopIteration:
        return
683471
def slice_before(predicate, iterable):
    
    if isinstance(predicate, string_type):
        predicate = re.compile(predicate)

    if hasattr(predicate, 'match'):
        predicate = predicate.match

    record = []

    for i, item in enumerate(iterable):
        if i == 0:
            record = [item]
            continue

        if predicate(item):
            yield tuple(record)
            record = [item]
        else:
            record.append(item)

    if record:
        yield tuple(record)
321045
public Object preOrder(NodeVisitor nodeVisitor, Node root) {
        return preOrder(nodeVisitor, Collections.singleton(root));
    }
704249
def iterchildren(self):
        """"""

        child_iter = self.model.iter_children(self.iter)
        return TreeModelRowIter(self.model, child_iter)
845321
def recursive_iterator(func):
    """"""
    tee_store = {}
    @_coconut.functools.wraps(func)
    def recursive_iterator_func(*args, **kwargs):
        hashable_args_kwargs = _coconut.pickle.dumps((args, kwargs), _coconut.pickle.HIGHEST_PROTOCOL)
        try:
            to_tee = tee_store[hashable_args_kwargs]
        except _coconut.KeyError:
            to_tee = func(*args, **kwargs)
        tee_store[hashable_args_kwargs], to_return = _coconut_tee(to_tee)
        return to_return
    return recursive_iterator_func
823281
def preorder(self, skip_seed=False):
        
        for node in self._tree.preorder_node_iter():
            if skip_seed and node is self._tree.seed_node:
                continue
            yield node
1163508
def postorder(self, skip_seed=False):
        
        for node in self._tree.postorder_node_iter():
            if skip_seed and node is self._tree.seed_node:
                continue
            yield node
1298882
def iter_up(self, include_self=True):
        """"""
        if include_self: yield self
        parent = self.parent
        while parent is not None:
            yield parent
            try:
                parent = parent.parent
            except AttributeError:
                return
463307
def peekiter(iterable):
    """"""
    it = iter(iterable)
    one = next(it)

    def gen():
        """Generator that returns first and proxy other items from source"""
        yield one
        while True:
            yield next(it)
    return (one, gen())
1320913
def get_parent(self):
        """"""

        parent_iter = self.model.iter_parent(self.iter)
        if parent_iter:
            return TreeModelRow(self.model, parent_iter)