Stream list of buckets through an iterator
514298
def stream_buckets(self, bucket_type=None, timeout=None):
        
        if not self.bucket_stream():
            raise NotImplementedError('Streaming list-buckets is not '
                                      "supported on %s" %
                                      self.server_version.vstring)
        bucket_type = self._get_bucket_type(bucket_type)
        url = self.bucket_list_path(bucket_type=bucket_type,
                                    buckets="stream", timeout=timeout)
        status, headers, response = self._request('GET', url, stream=True)

        if status == 200:
            return HttpBucketStream(response)
        else:
            raise RiakError('Error listing buckets.')
276587
public static <T> Stream<T> iteratorToStream(final Iterator<T> iterator) {
        return iteratorToStream(iterator, enableParallel);
    }
232720
function charybdis (iterator) {
  iterator = iterator || K
  const stream = new Writable({objectMode: true})
  const deferred = Promise.defer()

  const stats = stream.stats = {
    objects: 0,
    operations: 0,
    pending: 0,
    start: Date.now(),
    inEnd: 0,
    end: 0,
  }

  var sources = refcount()
  stream.on('pipe', onPipe)
  function onPipe (src) {
    sources.push()
    src.on('end', function () {
      sources.pop()
    })
    src.once('error', cleanup)
  }
  sources.on('clear', function () {
    stats.inEnd = Date.now()
    stream.emit('inEnd')
    tryResolve()
  })

  stream._write = function(obj, encoding, cb) {
    stats.objects++
    var op = iterator(obj)
    if (!op || !op.then) {
      tick()
      return cb()
    }

    stats.pending++
    stats.operations++

    tick()

    op.then(function () {
      stats.pending--
      tryResolve()
    },
    cleanup)

    cb()
  }

  function tryResolve() {
    // in streams ended and no operations pending?
    if (stats.inEnd && !stats.pending) { cleanup() }
    else tick()
  }

  function tick() {
    stream.emit('tick', stats)
  }

  function cleanup(err) {
    stream.removeListener('pipe', onPipe)
    sources.removeAllListeners()

    if (err) {
      deferred.reject(err)
    }
    stats.end = Date.now()

    deferred.resolve(stats)
  }

  stream.then = deferred.promise.then.bind(deferred.promise)

  return stream
}
575734
public static <T> List<T> toList(Iterator<T> iter) {
    List<T> buf = new ArrayList<>();
    while (iter.hasNext()) {
      buf.add(iter.next());
    }
    return buf;
  }
808840
def iter_chunks(self):
        
        for chunk_type, offset in self._iter_chunk_offsets():
            chunk = _ChunkFactory(chunk_type, self._stream_rdr, offset)
            yield chunk
221684
private CompletableFuture<List<EpochRecord>> getEpochRecords(String scope, String stream, int epoch, OperationContext context) {
        List<CompletableFuture<EpochRecord>> list = new ArrayList<>();
        list.add(streamMetadataStore.getEpoch(scope, stream, epoch, context, executor));
        list.add(streamMetadataStore.getActiveEpoch(scope, stream, context, true, executor));
        return Futures.allOfWithResults(list);
    }
1166121
public static <T> Collection<T> collect(Iterable<T> stream) {
        LinkedList<T> collection = new LinkedList<>();
        for (T e : stream) {
            collection.add(e);
        }
        return collection;
    }
1104534
def chunk(iterable, size):
    
    # TODO: only used in gui.mainwindow(deprecated)
    iterator = iter(iterable)
    while size:
        result = []
        try:
            for i in range(size):
                elem = next(iterator)
                result.append(elem)
            yield tuple(result)
        except StopIteration:
            if result:
                yield tuple(result)
            return
139420
public static <T> Stream<T> of(Iterable<T> iterable) {
    checkNotNull(iterable);
    return new StreamImpl<T>(iterable);
  }
1189991
def list(
            self,
            bucket: str,
            prefix: str=None,
            delimiter: str=None,
    ) -> typing.Iterator[str]:
        
        kwargs = dict()
        if prefix is not None:
            kwargs['prefix'] = prefix
        if delimiter is not None:
            kwargs['delimiter'] = delimiter
        bucket_obj = self._ensure_bucket_loaded(bucket)
        for blob_obj in bucket_obj.list_blobs(**kwargs):
            yield blob_obj.name
949325
private void readObject (ObjectInputStream s)
         throws IOException, ClassNotFoundException
    {
        // read in number of buckets and allocate the bucket array
        _buckets = createBuckets(s.readInt());
        _loadFactor = s.readFloat();

        // read in size (number of mappings)
        int size = s.readInt();

        // read the keys and values
        for (int i=0; i<size; i++) {
            int key = s.readInt();
            @SuppressWarnings("unchecked") V value = (V)s.readObject();
            put(key, value);
        }
    }
911678
def batch(iterable, chunk_size):
    
    i = iter(iterable)
    while True:
        r = list(itertools.islice(i, chunk_size))
        if not r:
            break
        yield r
741119
def _make_chunk_iter(stream, limit, buffer_size):
    """"""
    if isinstance(stream, (bytes, bytearray, text_type)):
        raise TypeError('Passed a string or byte object instead of '
                        'true iterator or stream.')
    if not hasattr(stream, 'read'):
        for item in stream:
            if item:
                yield item
        return
    if not isinstance(stream, LimitedStream) and limit is not None:
        stream = LimitedStream(stream, limit)
    _read = stream.read
    while 1:
        item = _read(buffer_size)
        if not item:
            break
        yield item
371343
function wrapIterator(iterator)
{
  var stream = this;

  return function(item, key, cb)
  {
    var aborter
      , wrappedCb = async(wrapIteratorCallback.call(stream, cb, key))
      ;

    stream.jobs[key] = wrappedCb;

    // it's either shortcut (item, cb)
    if (iterator.length == 2)
    {
      aborter = iterator(item, wrappedCb);
    }
    // or long format (item, key, cb)
    else
    {
      aborter = iterator(item, key, wrappedCb);
    }

    return aborter;
  };
}
1168517
async def chunks(source, n):
    
    async with streamcontext(source) as streamer:
        async for first in streamer:
            xs = select.take(create.preserve(streamer), n-1)
            yield [first] + await aggregate.list(xs)
136149
def list_bucket(self, bucket):
    
    self.response.write('Listbucket result:\n')

    page_size = 1
    stats = gcs.listbucket(bucket + '/foo', max_keys=page_size)
    while True:
      count = 0
      for stat in stats:
        count += 1
        self.response.write(repr(stat))
        self.response.write('\n')

      if count != page_size or count == 0:
        break
      stats = gcs.listbucket(bucket + '/foo', max_keys=page_size,
                             marker=stat.filename)
496543
def stream_array(self, generator):
        ''''''
        def chunkify(generator):
            log.debug('Data Stream STARTED')
            yield '['.encode()
            # In order to have commas only after the first value, we take the
            # first value of the generator manually
            try:
                yield jsonify(next(generator)).encode()
            except StopIteration:
                pass
            while True:
                try:
                    bit = next(generator)
                except StopIteration:
                    yield ']'.encode()
                    break
                else:
                    yield ',\n'.encode()
                    yield jsonify(bit).encode()
            log.debug('Data Stream ENDED')
        return chunkify(generator)