Esempio n. 1
0
def eat(iterator, amount):
    """Advance an iterator n-steps ahead. If n is None, eat entirely.

  Taken from the Python documentation. Under the PSF license.

  :param iterator:
      An iterator.
  :param amount:
      The number of steps to advance.
  :yields:
      An iterator.
  """
    # Use functions that consume iterators at C speed.
    if amount is None:
        # Feed the entire iterator into a zero-length deque.
        collections.deque(iterator)
    else:
        # Advance to the empty slice starting at position n.
        builtins.next(itertools.islice(iterator, amount, amount), None)
Esempio n. 2
0
def eat(iterator, amount):
  """Advance an iterator n-steps ahead. If n is None, eat entirely.

  Taken from the Python documentation. Under the PSF license.

  :param iterator:
      An iterator.
  :param amount:
      The number of steps to advance.
  :yields:
      An iterator.
  """
  # Use functions that consume iterators at C speed.
  if amount is None:
    # Feed the entire iterator into a zero-length deque.
    collections.deque(iterator)
  else:
    # Advance to the empty slice starting at position n.
    builtins.next(itertools.islice(iterator, amount, amount), None)
Esempio n. 3
0
def nth(iterable, index, default=None):
    """Returns the nth element out of an iterable.

  :param iterable:
      Iterable sequence.
  :param index:
      Index
  :param default:
      If not found, this or ``None`` will be returned.
  :returns:
      nth element of the iterable sequence.
  """
    return builtins.next(itertools.islice(iterable, index, None), default)
Esempio n. 4
0
def nth(iterable, index, default=None):
  """Returns the nth element out of an iterable.

  :param iterable:
      Iterable sequence.
  :param index:
      Index
  :param default:
      If not found, this or ``None`` will be returned.
  :returns:
      nth element of the iterable sequence.
  """
  return builtins.next(itertools.islice(iterable, index, None), default)
Esempio n. 5
0
 def walker(path, topdown=topdown, followlinks=followlinks):
   """Alternative walker."""
   yield builtins.next(os.walk(path,
                               topdown=topdown,
                               followlinks=followlinks))
Esempio n. 6
0
 def walker(path, topdown=topdown, followlinks=followlinks):
     """Alternative walker."""
     yield builtins.next(
         os.walk(path, topdown=topdown, followlinks=followlinks))