Internal generator that is able to retrieve ranges organized by step.
        Complexity: O(n) with n = number of ranges in tree.
161433
def _folded_slices(self):
        """"""
        if len(self) == 0:
            return

        prng = None         # pending range
        istart = None       # processing starting indice
        m = 0               # processing step
        for sli in self._contiguous_slices():
            start = sli.start
            stop = sli.stop
            unitary = (start + 1 == stop)   # one indice?
            if istart is None:  # first loop
                if unitary:
                    istart = start
                else:
                    prng = [start, stop, 1]
                    istart = stop - 1
                i = k = istart
            elif m == 0:        # istart is set but step is unknown
                if not unitary:
                    if prng is not None:
                        # yield and replace pending range
                        yield slice(*prng)
                    else:
                        yield slice(istart, istart + 1, 1)
                    prng = [start, stop, 1]
                    istart = k = stop - 1
                    continue
                i = start
            else:               # step m > 0
                assert m > 0
                i = start
                # does current range lead to broken step?
                if m != i - k or not unitary:
                    #j = i if m == i - k else k
                    if m == i - k: j = i
                    else: j = k
                    # stepped is True when autostep setting does apply
                    stepped = (j - istart >= self._autostep * m)
                    if prng:    # yield pending range?
                        if stepped:
                            prng[1] -= 1
                        else:
                            istart += m
                        yield slice(*prng)
                        prng = None
                if m != i - k:
                    # case: step value has changed
                    if stepped:
                        yield slice(istart, k + 1, m)
                    else:
                        for j in range(istart, k - m + 1, m):
                            yield slice(j, j + 1, 1)
                        if not unitary:
                            yield slice(k, k + 1, 1)
                    if unitary:
                        if stepped:
                            istart = i = k = start
                        else:
                            istart = k
                    else:
                        prng = [start, stop, 1]
                        istart = i = k = stop - 1
                elif not unitary:
                    # case: broken step by contiguous range
                    if stepped:
                        # yield 'range/m' by taking first indice of new range
                        yield slice(istart, i + 1, m)
                        i += 1
                    else:
                        # autostep setting does not apply in that case
                        for j in range(istart, i - m + 1, m):
                            yield slice(j, j + 1, 1)
                    if stop > i + 1:    # current->pending only if not unitary
                        prng = [i, stop, 1]
                    istart = i = k = stop - 1
            m = i - k   # compute step
            k = i
        # exited loop, process pending range or indice...
        if m == 0:
            if prng:
                yield slice(*prng)
            else:
                yield slice(istart, istart + 1, 1)
        else:
            assert m > 0
            stepped = (k - istart >= self._autostep * m)
            if prng:
                if stepped:
                    prng[1] -= 1
                else:
                    istart += m
                yield slice(*prng)
                prng = None
            if stepped:
                yield slice(istart, i + 1, m)
            else:
                for j in range(istart, i + 1, m):
                    yield slice(j, j + 1, 1)
187406
def recursive_iter(enumerables):
    '''
    
    '''
    if not is_collection(enumerables) or isinstance(enumerables, (basestring, dict)):
        yield enumerables
    else:
        for elem in enumerables:
            for sub_elem in recursive_iter(elem):
                yield sub_elem
240371
def list_of(*generators):
    

    class ListOfGenerators(ArbitraryInterface):
        """
        A closure class around the generators specified above, which
        generates a list of the generators.
        """

        @classmethod
        def arbitrary(cls):
            """
            Generate a list of the enclosed generators.
            """
            arbitrary_list = []
            for generator in generators:
                arbitrary_list += [
                    arbitrary(generator)
                    # max_length / len(generators):
                    for _ in range(arbitrary(int) % 100)
                ]
            return arbitrary_list

    ListOfGenerators.__name__ = ''.join([
        'list_of(', ', '.join(generator.__name__ for generator in generators),
        ')'
    ])
    return ListOfGenerators
721964
def traverse_levelorder(self, leaves=True, internal=True):
        '''
        '''
        q = deque(); q.append(self)
        while len(q) != 0:
            n = q.popleft()
            if (leaves and n.is_leaf()) or (internal and not n.is_leaf()):
                yield n
            q.extend(n.children)
619109
def traverse_levelorder(self, leaves=True, internal=True):
        ''''''
        for node in self.root.traverse_levelorder(leaves=leaves, internal=internal):
            yield node
141221
def uniform_iterator(sequence):
    """"""

    if isinstance(sequence, abc.Mapping):
        return six.iteritems(sequence)
    else:
        return enumerate(sequence)
1169816
function RangeIterator(range) {
	this.range = range;
	if (range.collapsed)
		return;

//[TODO] ensure this works
	// get anchors
	var root = range.commonAncestorContainer;
	this._next = range.startContainer == root && !DOMUtils.isDataNode(range.startContainer) ?
	    range.startContainer.childNodes[range.startOffset] :
	    DOMUtils.findClosestAncestor(root, range.startContainer);
	this._end = range.endContainer == root && !DOMUtils.isDataNode(range.endContainer) ?
	    range.endContainer.childNodes[range.endOffset] :
	    DOMUtils.findClosestAncestor(root, range.endContainer).nextSibling;
}
877398
def _slice_generator(self, index):
        """"""
        start, stop, step = index.indices(len(self))
        for i in range(start, stop, step):
            yield self.get_blob(i)
1160829
def slice_on_length(self, data_len, *addSlices):
        '''
        
        '''
        if len(self.ordered_ranges) + len(addSlices) == 0:
            return slice(None,None,None)
        ranges = self.ordered_ranges
        if len(addSlices) > 0:
            ranges = ranges + DimensionRange(*addSlices).ordered_ranges
        return self._combine_lists_of_ranges_on_length(data_len, *ranges)
478394
private CompiledForeachRangeArgs calculateRangeArgs(ForNode forNode, Scope scope) {
    RangeArgs rangeArgs = RangeArgs.createFromNode(forNode).get();
    ForNonemptyNode nonEmptyNode = (ForNonemptyNode) forNode.getChild(0);
    ImmutableList.Builder<Statement> initStatements = ImmutableList.builder();
    Expression startExpression =
        computeRangeValue(
            SyntheticVarName.foreachLoopRangeStart(nonEmptyNode),
            rangeArgs.start(),
            0,
            scope,
            initStatements);
    Expression stepExpression =
        computeRangeValue(
            SyntheticVarName.foreachLoopRangeStep(nonEmptyNode),
            rangeArgs.increment(),
            1,
            scope,
            initStatements);
    Expression endExpression =
        computeRangeValue(
            SyntheticVarName.foreachLoopRangeEnd(nonEmptyNode),
            Optional.of(rangeArgs.limit()),
            Integer.MAX_VALUE,
            scope,
            initStatements);

    return new AutoValue_SoyNodeCompiler_CompiledForeachRangeArgs(
        startExpression, endExpression, stepExpression, initStatements.build());
  }
1095666
def sort_genomic_ranges(rngs):
  """"""
  return sorted(rngs, key=lambda x: (x.chr, x.start, x.end))
1285714
def from_list(commands):
    
    def subtrees(commands, level):
        if not commands:
            return

        acc = []
        parent, *commands = commands

        for command in commands:
            if command['level'] > level:
                acc.append(command)
            else:
                yield (parent, acc)
                parent = command
                acc.clear()
        yield (parent, acc)

    def walk(commands, level=0):
        return [
            {
                'description': key['description'],
                'children': walk(subtree, level + 1),
                'id': key['id']
            }
            for key, subtree in subtrees(commands, level)
        ]

    return walk(commands)
367659
def fromlist(cls, rnglist, autostep=None):
        """"""
        inst = RangeSet(autostep=autostep)
        inst.updaten(rnglist)
        return inst
639824
private Hashable find(Range<Token> range)
    {
        try
        {
            return findHelper(root, new Range<Token>(fullRange.left, fullRange.right), range);
        }
        catch (StopRecursion e)
        {
            return new Leaf();
        }
    }
579061
def unconsumed_ranges(self):
        
        res = IntervalTree()

        prev = None

        # normal iteration is not in a predictable order
        ranges = sorted([x for x in self.range_set], key=lambda x: x.begin)

        for rng in ranges:
            if prev is None:
                prev = rng
                continue
            res.add(Interval(prev.end, rng.begin))
            prev = rng
        
        # means we've seeked past the end
        if len(self.range_set[self.tell()]) != 1:
            res.add(Interval(prev.end, self.tell()))

        return res
1138053
def mygenerator(n=5, n_edges=5):
    '''
    
    '''
    G = nx.Graph()

    for i in range(n):
        G.add_node(i)
    
    for i in range(n_edges):
        nodes = list(G.nodes)
        n_in = choice(nodes)
        nodes.remove(n_in)  # Avoid loops
        n_out = choice(nodes)
        G.add_edge(n_in, n_out)
    return G
160387
def ranges(self):
        
        steps = []
        for p in self._parameters:
            # inclusive range
            if p['parameter'] == 'filename':
                steps.append(p['names'])
            else:
                if p['step'] > 0:
                    start = p['start']
                    stop = p['stop']
                    if start > stop:
                        step = p['step']*-1
                    else:
                        step = p['step']
                    # nsteps = np.ceil(np.around(abs(start - stop), 4) / p['step'])
                    nsteps = self.nStepsForParam(p)
                    # print 'nsteps', np.around(abs(start - stop), 4), p['step']
                    # print 'start, stop, steps', start, stop, nsteps
                    step_tmp = np.linspace(start, start+step*(nsteps-2), nsteps-1)
                    # print 'step_tmp', step_tmp

                    # if step_tmp[-1] != stop:
                    step_tmp = np.append(step_tmp,stop)
                    # print 'step range', step_tmp

                    steps.append(np.around(step_tmp,4))
                else:
                    assert p['start'] == p['stop']
                    steps.append([p['start']])
        return steps